• Post Reply Bookmark Topic Watch Topic
  • New Topic

threading in swing  RSS feed

 
sushant prabhu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hope my query is valid.
I hav read that threading in swing is handled by a separate thread called EVentQueue thread. It is also said that whenever threading is used in threads we hav to take care that we dont manipulate the swing components thru arbitrary running of multiple threads.
Can someone please ellaborate on th above and on the speciaility of this event queue thread
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about the EventQueueThread, but any time you use 2 or more threads, you just have to be careful that the objects that they have access too are either explicitly for that thread, or that the changes the threads can make to common/shared objects will not break any of the other threads. This applies to all objects, not just swing components.
for example, if you had an int variable that one thread expected to be between 1 and 10 and another thread changed it to 12 for some reason, it would break your first thread when it tried to use the out of range value. The same applies to a JFrame. If one thread has created and displayed a JFrame and a second thread destroys that JFrame at some point, further references to that JFrame by the first thread obviously woun't do much good. Now some things that different threads may do to a shared swing object are fine. Changing the background color of the JFrame for example.
It really is just a matter of making sure that any changes a thread CAN make to a shared object will not break any other threads that have access to it.
I hope this helps at least a little.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!