Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread safe GUI

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I have made my GUI thread safe as per the Java tutorials buy launching my windows with:


However, I notice this code is absent from the SCJD book and was wondering if there is a reason not to use it in a multi-threaded environment such as this project.

Thanks,
Matt
 
Roel De Nijs
Sheriff
Posts: 10591
140
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the search engine: thread1 and thread2.

Matt Pavlovich wrote:a multi-threaded environment such as this project

My client is not multi-threaded, my server is. If I would perform a major time-consuming task and I want not to freeze my GUI I would use the SwingUtilities.invokeLater(), but in this project I don't see any advantages.
 
Marcel van den Boer
Greenhorn
Posts: 21
Java Linux Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:If I would perform a major time-consuming task and I want not to freeze my GUI I would use the SwingUtilities.invokeLater()


They invented SwingWorker for that . If you use invokeLater() for time consuming tasks, the GUI would freeze anyway.

It's true you'll probably won't absolutely need to use invokeLater() to construct your GUI, but as I understand it, it is a good practice to do so anyway. The Swing documentation does not say you should only use invokeLater() in a multi-threaded application, it just says you should use it when constructing your GUI (http://download.oracle.com/javase/6/docs/api/javax/swing/package-summary.html).

But you must do what you feel is right, of course...
 
Roel De Nijs
Sheriff
Posts: 10591
140
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcel van den Boer wrote:They invented SwingWorker for that . If you use invokeLater() for time consuming tasks, the GUI would freeze anyway.

Oh, my mistake I have limited Swing experience, for my current project (desktop application) we are using RCP as technology, no Swing anymore.
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic