Java: Method does not return. (XComponent.dispose

I use the OpenOffice API from my Java Program to handle Documents for me. Sometimes (once every 100k or so calls) the dispose method of a Document does not return, the CPU load stays at 100% but nothing seems to happen.

How should I act / code correctly in this situation?

My current approach is to wait for the dispose to succeed for two seconds. If it does not I try to terminate OpenOffice through the appropriate API. If that fails as well (as I would expect) then I kill the soffice process with a call to

XDesktop xDesk = (...) // achive desktop
xDesk.terminate();
Runtime.getRuntime().exec("pkill soffice"); // "taskkill /IM soffice" on windows

and then call

disposeThread.stop();

to the Thread that initially tries to dispose the XComponent. Now the Java API says that Thread.stop() should not be used (and there are valid arguments to that) so I'm wondering if there are any better solutions that what I did.


It seems like you have some pretty novel ways to work around a strange rare bug.

The way I see it is that while the Java API states that Thread.stop() should not be used, the same can be said that the the OpenOffice Document.dispose() should always return. Even if it is a rare occurrence, it is still a bug, as it does not finish and return a value nor does it throw an exception because of an invalid state. It just runs in an infinite loop, therefore it is a bug.

As it is a workaround, I see no problems with using Thread.stop() if you need to prevent your application from hanging. The disclaimer about why it should not be used is more intended to prevent poorly developed multi-threaded applications as it can absolutely be abused.

链接地址: http://www.djcxy.com/p/57178.html

上一篇: 哪里可以找到所有供应商的清单

下一篇: Java:方法不返回。 (XComponent.dispose