确定打印机是否可以在没有查找的情况下处理打印作业

ari*_*rin 65 java printing performance

我一直在争夺PrintServiceLookup; lookupPrintServices(DocFlavor flavor, AttributeSet attributes)使用初始磨合,在我们的应用程序中检测打印机的方法过于缓慢.拥有100多台网络打印机的客户端报告说,执行此代码的行为在第一次运行时性能很差.

在看到查找结果被缓存后,我最初在一个单独的线程中部署了一个虚拟查找(在启动时执行).但是,对于特定客户端,此解决方案无效.

我目前没有他们的环境,也无法看到导致确切性能问题的原因.

我试图看看是否PrintService支持给定MediaSizeName 而不执行查找DocFlavorAttributeSet.所以我拉出所有可用的PrintServices和默认值PrintService:

private static final PrintService[] PRINTSERVICES = 
   PrintServiceLookup.lookupPrintServices(null, null);

private static final PrintService DEFAULTSERVICE = 
   PrintServiceLookup.lookupDefaultPrintService();
Run Code Online (Sandbox Code Playgroud)

然后,从客户端请求中获取PrintServiceMediaSizeName.最后,我问PrintService是否MediaSizeName支持:

private void checkPrintServiceForMediaSize(PrintService pservice) throws MediaSizeNotSupportedException{
     if(!pservice.isAttributeValueSupported(_mediaSizeName,null,null))
            throw new MediaSizeNotSupportedException("This media size is not supported by the selected printer.");
     }
Run Code Online (Sandbox Code Playgroud)

API声明时isAttributeValueSupported(Attribute attrval,DocFlavor flavor,AttributeSet attributes)被调用,零DocFlavorAttributeSet

此方法指示此Print Service是否支持给定的打印属性值以获取doc flavor和属性集的某种可能组合

到目前为止表现得很好.但是,如果打印机支持所选页面大小,我不完全确定这是否是执行方式.

非常感谢您对此问题的反馈和经验.


更新

在我实施我的方法的时候,我的工作站决定遇到严重的网络问题,这花了我一段时间才弄明白.最后,我的实现已经使用网络工具SoftPerfect连接仿真器(模拟网络负载)进行了测试,结果没有显着改善.

我将继续测试并更新这个问题.希望我能找到解决方案并在这里与人们分享.我猜的是初始查找:

private static final PrintService[] PRINTSERVICES = 
   PrintServiceLookup.lookupPrintServices(null, null);
Run Code Online (Sandbox Code Playgroud)

仍在引发问题.


更新2

beta版本最终在客户端环境中进行了测试,并且打印对话框的性能提高了大约5倍(在相同的环境下,打印机的初始拉动现在大约需要1分钟,而大约5分钟).最初的等待时间仍然不是可接受的时间,但是,我现在能做的最好.我们还从客户那里听说正在使用打印服务器并遵循评论中的建议(@Wardy),我将继续朝着这个方向前进.希望我们可以利用打印服务器的优势.

小智 0

如果打印机列表存储在 LDAP 中,您可以尝试使用LDAP查找打印机。