0

Understood that Swingworker should only use to process long processes such as loading data from DB to UI, or from UI to DB to avoid GUI freeze.

But I've a scenario where I need to process a opened document from UI thread, and it will take a while to go through the processes. I was wondering does this process suitable to be placed in Swingworker since it is both coming from UI thread? Will it caused concurrency issue?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Luke.T
  • 11
  • 1
  • 6
  • 1
    That will depend, is the `Document` going to be changed either by you processing it or via the GUI while the processing is occurring. If yes, then you have an issue. If not, then the only issue you have is keeping the UI responsive for the user, so a `SwingWorker` may be suitable – MadProgrammer Jun 24 '15 at 02:47
  • Two approaches are examined [here](http://stackoverflow.com/q/25526833/230513). – trashgod Jun 24 '15 at 03:04
  • It is to highlight the document, the GUI will be freezed if large document loaded. The highlight will be added back to the document as annotation. – Luke.T Jun 24 '15 at 03:33
  • Okay, you need a "copy" of the document, or your need to prevent the UI from updating it while you are processing it. You can use a `SwingWorker`, as it can return what ever object you want from the `doInBackground` method. You can use a `PropertyChangeListener` or override the `done` method to monitor the state of the worker, so you know when it's complete. Once completed, reapply the, know updated, document to your view – MadProgrammer Jun 24 '15 at 03:45
  • Thx @MadProgrammer. That helps me to see the picture clearer. – Luke.T Jun 26 '15 at 01:25

0 Answers0