Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java printing & multithread

I wrote a little snippet called by php to print .postscripts files on a pre-defined network printer.

While i print one file only, everything goes well, but when i try to set up a multi-thread printing management to send more then 1 file at once to the printer, only the first one comes out.

The problem is that the PrintJobEvent PrintJobEvent.JOB_COMPLETE and PrintJobEvent.JOB_FAILED never happens, and the only events sent back by the spooler are DATA_TRANSFER_COMPLETE and NO_MORE_EVENTS .

I searched around the web and Sun forums, but no wayto find an answer. Thank you previously for any help :)

last minute editing : if i run the app in debug mode from netbeans, and i interrupt the first thread manually, the second file is sent to the printer... so i imagine that it has to works someway

like image 552
kitensei Avatar asked Aug 30 '26 12:08

kitensei


1 Answers

It really does not make sense to send multiple files in parallel to a printer. Why don't you create a queue and send the jobs to a Thread that would sequentially read the data from the queue and then send the results to the printer. If not you will need to serialize the output.

You might also run into issues with initializing the printer on multiple threads.

A Printer can only print one job at a time anyways.

like image 156
Romain Hippeau Avatar answered Sep 01 '26 00:09

Romain Hippeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!