I created a Swing GUI application to perform all long-running tasks in the background by placing them into subclasses of SwingWorker, which worked well. Now I want to add some 'dry run' functionality before the real changes happen on all the backend systems. For this I added a boolean property to my SwingWorker and want to run it once with true, once with false.
In practice, and per design a Swing worker can only be used once.
With that the reuse is not possible. But if I want to be able to run that beast multiple times, how should I implement the application? Does it make sense to subclass SwingWorker at all, or use a strategy pattern so my code is the strategy that the SwingWorker just triggers? Somehow I feel that all the doInBackground/publish/process/done patterns would loose their meaning.
Having spent some more thoughts about the dry run probably that feature is not what I want anyway. Running the same functionality again, just a minute later may result in different actions: the backend system's state need not be that stable, and thus the records displayed to be touched in the dry run need not be the records touched in the real run.
So I think I will create a 'dry run' feature that examines the backend systems and comes up with a plan. If the user so wishes, that plan gets executed.
As these are two different actions I cannot use the same SwingWorker anyway. I will use one to create a plan and another to execute the plan.