java - 打印机竞争状况?

标签 java printing

所以我正在修改一些代码。无需详细了解其实际用途,只需创建一个文件然后将其发送到打印机即可对其进行总结。基本上如下:

File file = new File("/tmp/12345.pdf");
//Lots of magical code that creates/writes to said file
...
...
...
//sendToPrinter essentially builds up a print command to send to /usr/bin/lp and then executes it.
sendToPrinter(printer, details, file);

file.delete();// This is the line I'm curious about.

我的问题是对 lp 的调用是在我们到达 file.delete() 之前进行的。但是,这是否存在创建竞争条件的风险,即我实际上最终在打印机准备就绪之前删除了文件?

从初步测试来看,我还没有发现问题,但这件事让我感到困扰。我这样做是否造成了竞争条件的风险?

编辑:根据评论进行澄清。是的,我正在使用 lp 并且 sendToPrinter 似乎正在等待返回代码。该代码不是异步的。

最佳答案

来自文档

The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,

t.join(); causes the current thread to pause execution until t's thread terminates.

http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()

关于java - 打印机竞争状况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32829779/

相关文章:

javascript - 打印操作后 Bootstrap Modal 关闭按钮问题

java - BufferedReader 不读取最后一行

objective-c - 如何检测打印操作何时完成?

Java:收据打印机自动切割

Java嵌套for循环打印输出

java - Flexiforce 到 Uno 到键盘。工作正常,但未达到预期效果

java - 是否可以仅在内存中以编程方式编译 java 源代码?

Haskell - 打印数字

Java replaceAll ("\\s+") 与 replaceAll ("\\\\s+")

java - 特定时区日历中的日期 getTime()