This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I think a method: /** * Wait until task finishes or timeout expires. * @param timeout in milis * @return false if timeout expired */ public boolean waitFinished (int timeout) throws InterruptedException could be useful.
Target milestone -> 3.3.1.
Set target milestone to TBD
*** Issue 45562 has been marked as a duplicate of this issue. ***
Adding waitFinished(long timeout) or (int timeout) is possible, but is not that simple how it might look. The problem is that Task is as well API as well SPI and there are some clients that override waitFinished (like FolderInstance) and relly on it being called. So introducing new method has to count deal with cases when original waitFinished is overriden and call it. This adds a lot of compliations to the implementation. On the other hand, it seems logical to have the time out method, Future has it too: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html I've written a bunch of testcases and were able to satisfy all of them. So if this passes review, I am ready to commit this for promoE. Btw. should be probably related to issue 33467 which also works with InterruptedExceptions.
Created attachment 16561 [details] The implementation and tests
I think it would make more sense for the default impl to throw an UnsupportedOperationException rather than delegate to the no-timeout version. At least you would then notice right away that your timeout was not being honored, rather than thinking everything was working but then running into a random deadlock months later because there was actually no effective timeout.
The timeout is effective even when delegating to waitFinished(). That is the whole point of the complicated logic in Task. Just a bit inefficient (replans to another thread). The problem with UnsupportedOperationException is that it would force me to implement the solution in each subclass of Task and forms really unusable API. The most important thing is that RequestProcessor.Task implements this correctly and that FolderInstance works fine (due to the delegation). But as I said I am ready to not integrate the code if there are no real requirements for it.
This could greatly simplify call add to NbClipboard as part of fix for issue 41098
As there is at least one case where this api could simplify the code a lot and there were no objections, I am going to apply the fix tomorrow. I'll increase the version of openide to 5.0.
It's 3 years old RFE and I was too brief that time. $ grep -r "16849" * core/src/org/netbeans/core/NbClipboard.java: // API enhancement in issue 16849 - we would just use: ^C - one usage is enough
cvs ci -m "#16849: Adding Task.waitFinished(long) and thus simplifying the code in NbClipboard a lot" Checking in openide/openide-spec-vers.properties; /cvs/openide/openide-spec-vers.properties,v <-- openide-spec-vers.properties new revision: 1.161; previous revision: 1.160 done Processing log script arguments... More commits to come... Checking in openide/api/doc/changes/apichanges.xml; /cvs/openide/api/doc/changes/apichanges.xml,v <-- apichanges.xml new revision: 1.227; previous revision: 1.226 done Processing log script arguments... More commits to come... Checking in openide/src/org/openide/util/RequestProcessor.java; /cvs/openide/src/org/openide/util/RequestProcessor.java,v <-- RequestProcessor.java new revision: 1.81; previous revision: 1.80 done Checking in openide/src/org/openide/util/Task.java; /cvs/openide/src/org/openide/util/Task.java,v <-- Task.java new revision: 1.26; previous revision: 1.25 done Processing log script arguments... More commits to come... Checking in openide/test/unit/src/org/openide/util/RequestProcessorTest.java; /cvs/openide/test/unit/src/org/openide/util/RequestProcessorTest.java,v <-- RequestProcessorTest.java new revision: 1.18; previous revision: 1.17 done Checking in openide/test/unit/src/org/openide/util/TaskTest.java; /cvs/openide/test/unit/src/org/openide/util/TaskTest.java,v <-- TaskTest.java new revision: 1.3; previous revision: 1.2 done Processing log script arguments... More commits to come... Checking in core/src/org/netbeans/core/NbClipboard.java; /cvs/core/src/org/netbeans/core/NbClipboard.java,v <-- NbClipboard.java new revision: 1.22; previous revision: 1.21