I am gray

« Previous month (Jan 2008) | Main | Next month (Mar 2008) »
Středa III 19, 2008

Default RequestProcessor in NetBeans can not cancel running Tasks

RequestProcessor is quite useful class for programming in NetBeans. You are not supposed to create your own threads (quite similar limitation is common for different managed environments such as application servers) and RequestProcessor.Task is quite comfortable (and a bit more high level) way to perform concurrent tasks.
The common pattern to use it is
RequestProcessor.Task myTask = RequestProcessor.getDefault().post(aRunnable)
This is a pretty good way, until you try myTask.cancel(). In such a situation, there are two possibilities. If the myTask has not started yet, it is canceled and will not be started ever. If it has already started, it is not interrupted.
So if you want to start some longer tasks and you would like to cancel even when already running, you must create your own RequestProcessor using this constructor with the (last) parameter interruptThread set to true.