We need to specify a printer to print word doc by java(jacob), and this may happen in a multithreaded environment.
At the beginning we use this method but concurrency problems occurred. When two threads execute this code at the same time, the printer of the two print tasks will be mixed.
word.setProperty("ActivePrinter", new Variant(printerName));
So we found another way to achieve it with FilePrintSetup, in this article. https://support.microsoft.com/en-US/topic/activeprinter-property-in-word-sets-system-default-printer-4b4afb8f-cbc1-1187-14cc-a97fdd0f596e
Dispatch wordBasic = Dispatch.call(word, "WordBasic").toDispatch();
Dispatch.call(wordBasic, "FilePrintSetup", new Variant(printerName), new Variant(false));
But when we actually use it, the second parameter can only pass
false, because when
true is passed, there will be a UI dailog of the printer to block the continued execution of the program, as shown in the figure below.
false, the same concurrency problems still occur. Is there any good solution? Thank you