I have a problem concerning launching multiple instances of a Altova MapForce (an exe-file) giving each instance it's own thread. The thread class looks like this:
This works fine as long as I only launch one instance. Whenever I launch multiple instances the result becomes unpredictable. What most often happens is that all threads terminates almost right away, and it looks like that the mapforce.exe simply chrashes because the logfiles are empty (which they are usually not).
Running MapForce.exe from a Windows command prompt returns immediately, which for me indicates that the program launches itself in a som sort of thread and handles back control to the cmd-prompt. This allows me to also start multiple instances from the command prompt and this works without problems.
What is the difference between the two scenarios: Executing multiple MapForce.exe from Java vs. launching them from the cmd-prompt? There must be some difference, since the former simply doesn't work.
Try putting a println statement after the p.waitFor call on line 20. If mapforce.exe returns immediately when you run it from a command prompt, I suspect that waitFor will also return immediately, which means your thread will also terminate. Not sure why this would cause the mapforce.exe instances to crash though.
Joined: Nov 10, 2011
I debugged that part already. p.waitFor() actually waits for the MapForce-process to complete and doesn't return right away (as it would do in a command prompt). I don't know what technique MapForce.exe is using that makes this difference. So when p.waitFor() returns it's because MapForce.exe has either completed it's task or chrashed. The latter being the case when I launch multiple threads as described above.
The call to p.waitFor() could cause your program to wait indefinitely if you do not clear the process' output and error streams. Not following the instructions in the article may not be the cause of your problems, but it's better to follow them anyway.
Joined: Nov 10, 2011
Ok - I'll handle that. But it's not the cause of my problem, and I still don't see anything in that article that explains what is going on.