I have a class that takes in a number of SwingWorkers
and runs them one at a time in a certain order. I use a ReentrantLock
to make sure that only one worker runs at a time. Normally I would always unlock in a finally clause, but I need it to stay locked until the worker completes.
nextWorker.getPropertyChangeSupport().addPropertyChangeListener("state",
new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getNewValue().equals(SwingWorker.StateValue.DONE))
{
executionLock.unlock();
}
}
});
If this is not the case, is done() guaranteed to be called? I would prefer not to call unlock this way, as it would violate encapsulation to some degree.
Due to the nature of the project it is likely that this will come up in a code review. In that case it would be helpful to have a verifiable source. So far I have been unable to find one.
personally I tried everything possible with
SwingWorker
, but always ends me withdone()
, but I think that there no guarantee that implemented methods fromFuture
ends correctly, still there this Bugno idea about your code about lock/unlock another thread or process, but I suggest to use
Executor
for multithreading,how to get exceptions from
SwingWorker
Taskpersonally I never ever had bad experiences with
SwingWorker
or some un-expected lack, but allMultiThreading
Gurus told aboutSwingWorker
for Production code never, there is still required use ofRunnable#Thread
instead ofSwingWorker