繁体   English   中英

带有 Java 1.5 的 Red Hat Linux 上的 PrintServiceLookup.lookupPrintServices 有时会返回包含 NULL 对象的数组

[英]PrintServiceLookup.lookupPrintServices on Red Hat Linux with Java 1.5 sometimes returns array with NULLs insted of objects

我们在 RHL 上获取打印机列表时遇到了这个奇怪的问题。 我写了一小段代码来演示正在发生的事情:

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocFlavor.INPUT_STREAM;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;

public class PrintTest
{
  public static void main(String[] args)
  {
      PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);
      System.out.println(pservices.length);

      for( int y = 0; y < pservices.length; y++ ){
        System.out.print(y + " - " );
        System.out.println(pservices[y]);
      }
  }
}

这是结果:

0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - null
1 - null
2 - null
3 - null
4 - null
5 - null
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - null
1 - null
2 - null
3 - null
4 - null
5 - null

(我连续多次运行代码)。

如您所见,有时我们可以获得打印机列表(系统上配置了 6 台),有时我们可以获得长度为 6 的数组,但没有对象,只有空值:/。

请帮我诊断问题我在谷歌上做了一个快速搜索,但似乎没有什么适合这个。

这是服务器上的 java 版本: java version "1.5.0_30" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_30-b03) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_30-b03 , 混合模式)

不幸的是,我无法改变这一点。

编辑:以下是 CUPS 的日志(不知道是否重要):

D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:25 +0100] cupsdCloseClient: 8
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:25 +0100] cupsdCloseClient: 8
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default client-error-not-found: No default printer
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Printers
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=0 (successful-ok)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default client-error-not-found: No default printer
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Printers
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=0 (successful-ok)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 8

unix/linux 平台上的 CUPS 和 java jre 存在问题,要查看更多信息,您可以将sun.print.ippdebug设置为true 在您的情况下,它看起来像 jre 中的这个错误,因此将sun.java2d.print.polling设置为true应该会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM