簡體   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