• Post Reply Bookmark Topic Watch Topic
  • New Topic

Communication between threads

 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a swing interface that contains a panel with a chart, table, and start button. The start button starts a long running (think weeks) optimization algorithm that spawns threads for optimizing sub models. The optimized parameters and cost function should be tabulated / plotted back on the panel. What are the options for the sub model threads communicating back with the swing thread for displaying the information?

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> What are the options for the sub model threads communicating back
> with the swing thread for displaying the information?

single option, must be on the EDT via
SwingUtilities.invokeLater(...)
 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant to say what are the options for communicating interim results from the worker threads back to the swing thread? One option is the publish/process paradigm. Are there other options?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a javax.swing.Timer to periodically control check the progress of the optimization and update GUI with current information (eg. once a second). Of course, the timer runs on Event Dispatch Thread, so you'd have to make sure he sees the current state of the optimization in a consistent manner.

Edit: sorry, once in a while I mix up "control" and "check".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!