Java: Method does not return. (XComponent.dispose
Asked Answered
B

1

7

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.

Blocker answered 12/1, 2012 at 13:56 Comment(7)
This is one of those questions where depending on how it is worded, it might be appropriate for Programmers, but I feel like this is technical and implementation specific enough that it should probably be on StackOverflow.Fricke
@Fricke I thought about that but decided against it. If it were a question on how to handle my specific problem I would have put it there, but I have already found a working solution for my problem and now I'm asking if there is a better concept, rather than a specific solution. But yeah, its depending on how its worded.Blocker
@RobZ This really is not a Open Office specific question. My Open Office Situation here is just an example.Blocker
@AngeloNeuschitzer - Right now it is looking like this question will be migrated. Maybe let this one go over to SO (specific solution) and then open a new, very generally phrased, one here on Programmers? I'm interested in the best practice as well but I could see someone working with OpenOffice looking for a specific solution.Dysentery
I think the correct approach would be to file a bug to whoever released the problematic code.Murage
@Murage This is the correct long term solution. Short term however you need to use whatever dirty tricks you have to get things working.Fricke
@Murage Yeah, I know. But I don't have the time atm to file a bug that happens every 100k runs if it would need me to checkout the current API and see if it is there as well, etc. etc. But in principle you are right thats what I should do.Blocker
F
4

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.

Fricke answered 12/1, 2012 at 15:34 Comment(1)
Thank you for your Answer, I waited for over a month now to see if anybody could come up with a better idea, but unfortunately not... My current solution is to use system commands (ps and kill) to terminate OOo in this situation because it hangs totally. It seems like a huge mess in there :( Anyway, I'll mark your answer as correct, thanks again.Blocker

© 2022 - 2024 — McMap. All rights reserved.