I was talking with Maxence about background job execution. I'm sending
this email to discussion list so we all can share ideas about it.
My ideas of fixing ProgressDialog:
1) extract the run() method from ProgressDialog to a new class (JobInfo)
2) this new class will make computations for the job progress
3) these computations should be accessible (create fields and getters instead of local variables)
It will make GUI update possible not only on ProgressDialog, but also on background job execution monitor (I'm thinking about JTable here)
4) synchronize calls when they should be synchronized
I'm thinking about three possible solutions for threading
1)
a) job thread
b) job monitor thread (making job progress computations)
c) EDT (Event Dispatch Thread)
There should be synchronization between (a) and (b) - job monitor
thread should update job progress info (JobInfo)
and between (b) and (c) - GUI should be updated in EDT with new values.
This situation is similar to the one that currently is implemented but changes in the GUI are now made in (b) and should be made in (c).
All computations should be separated from all GUI updates, and GUI updates should be scheduled using SwingUtilities.invokeLater.
If we use JTable and TableModel it can get tricky.
2)
a) job thread
b) EDT with swing.Timer for job monitor
we need only one synchronization between (a) and (b)
Job monitor will not be in a separate thread but will be scheduled using the swing timer. One loop of the current run() method will be executed for one
timer event.
The task from swing timer runs in EDT thread so no sync will be needed for updating the GUI - after calculating new values we could update GUI elements.
The computations performed in the job monitor are not expensive so they can be run in EDT thread without a user noticing it.
3)
use SwingWorker (it requires Java 6), I have not investigated it further.
I've created quick prototype for (1) but now I think that solution (2)
is better.
What do you think about these solutions?
This is only "job progress" part, a first step to introduce background
jobs. There are also other issues (e.g. FileJob <-> FileTable sync). I
want first to solve this "progress" task and then look into other
issues.
Best Regards
Mariusz