"Uncaught" InterruptedException when interrupting a Thread running NOA
| Release: | 2.0.8 |
|---|---|
| Area | Functionality |
| Type | Bug |
| Severity | Medium |
| Submitted by | Blizzard |
| Submitted on | 14-02-2007 |
| Responsible |
—
|
| State | closed |
first of all nice work you have down with NOA.
Now to my issue. We are running NOA inside a Thread which may be interrupted at random times in order to be able to receive some Messages we sent. When the Thread is interrupted while running a NOA application the application fails and the following stacktrace is logged to the Console:
ag.ion.bion.officelayer.application.OfficeApplicationException: java.lang.InterruptedException: sleep interrupted(Note that the Stacktrace is for NOA 2.0.7 but i tested it with 2.0.8 also, which isn't available to me atm.)
at ag.ion.bion.officelayer.internal.application.LocalOfficeApplication.openConnection(LocalOfficeApplication.java:161)
at ag.ion.bion.officelayer.internal.application.AbstractOfficeApplication.activate(AbstractOfficeApplication.java:118)
at ag.ion.bion.officelayer.internal.application.AbstractOfficeApplication.activate(AbstractOfficeApplication.java:134)
at examples.november2006.NoaODTManipulation.getOfficeInstance(NoaODTManipulation.java:171)
at examples.november2006.NoaODTManipulation.openTextdocument(NoaODTManipulation.java:238)
at examples.november2006.NoaODTManipulation.createOODocFromTemplate(NoaODTManipulation.java:111)
at examples.november2006.OO_OfferCreator.createOODocFromTemplate(OO_OfferCreator.java:146)
at examples.november2006.PrepareExampleOO_OfferCreator.run(PrepareExampleOO_OfferCreator.java:297)
at de.aristaflow.adept2.base.runtimeenvironment.defaultimplementation.DefaultComponentExecutor.run(DefaultComponentExecutor.java:277)
Caused by: com.sun.star.uno.RuntimeException: java.lang.InterruptedException: sleep interrupted
at ag.ion.bion.officelayer.internal.application.connection.LocalOfficeConnectionGhost.connect(LocalOfficeConnectionGhost.java:675)
at ag.ion.bion.officelayer.internal.application.connection.LocalOfficeConnectionGhost.getComponentContext(LocalOfficeConnectionGhost.java:495)
at ag.ion.bion.officelayer.internal.application.connection.LocalOfficeConnection.openConnection(LocalOfficeConnection.java:176)
at ag.ion.bion.officelayer.internal.application.LocalOfficeApplication.openConnection(LocalOfficeApplication.java:157)
... 8 more
I traced this down to line 615 (NOA 2.0.7) in which you call Thread.sleep() which when interrupted throws the InterruptedException. But the InterruptedException isn't caught correctly instead it is caught in the generic catch(Exception) statement at the end of the Method then wrapped into a RuntimeException and rethrown.
Andreas
- Run NOA inside a different Thread. Then while the connection to OO is established call Thread.interrupt().
Hello,
could You please send me some sample code where this error occurs?
Best regards,
Markus
Hello Markus,
I attached a small Test Case.
Greets,
Andreas
Hello Andreas,
with Your Example I could reproduce this. What do You think how we should handle it? Any Ideas?
By the way the Thread.sleep() call is not the only one, that throws this exception. A method of OpenOffice.org we call does this also as I commented out the Thread.sleep() code.
Regards,
Markus
Hello Markus,
your application doesn't need to be interruptible so I would just swallow the Exception and maybe set a flag to restore the interrupted state after you're finished. For example something like this:
<pre>...
<b>boolean interrupted = false;</b>
try {
initialObject = resolve(xLocalContext, url);
}
catch (com.sun.star.connection.NoConnectException noConnectException) {
if (officeProgressMonitor != null)
officeProgressMonitor.beginSubTask(Messages.getString("LocalOfficeConnectionGhost_monitor_starting_native_service_message")); //$NON-NLS-1$
OfficeService officeService = new OfficeService();
officeService.startupService();
long nMaxMillis = System.currentTimeMillis() + 1000 * officeService.getStartupTime();
while (initialObject == null) {
try {
Thread.sleep(500);
initialObject = resolve(xLocalContext, url);
if(officeProgressMonitor != null) {
if(officeProgressMonitor.isCanceled())
return null;
}
}
catch (com.sun.star.connection.NoConnectException innerNoConnectException) {
if (System.currentTimeMillis() > nMaxMillis)
throw innerNoConnectException;
}
<b>catch (java.lang.InterruptedException e) {
interrupted = true;
}</b>
}
}
finally {
}
<b>if (interrupted)
Thread.interrupt();</b>
...</pre>
If you want to have some more thoughts you can have a look at http://www-128.ibm.com/developerworks/java/library/j-jtp05236.html which gives a view thoughts about dealing with InterruptedExceptions.
Greets
Andreas
Hello everyone,
I just wanted to ask what's the status of this issue and if there is any chance that this will be fixed in the near future.
Regards,
Andreas
Hello,
I imlemented Your code change in the current version. I updated it today to include it. Please download again ang give some feedback if it works now.
Regards,
Markus



OOTest.java
(