• Post Reply Bookmark Topic Watch Topic
  • New Topic

it seems my thread fainted  RSS feed

 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program contains several threads. One updates a clock, one execute a database query, and one scrolls a JTable (actually, I extended JTable, and added a scroll() method that effectively calls scrollRectToVisible without any loops, i.e., the jTable.scroll() method below cannot hang).

Now, I'm really confused about the following: After several hours of running, the JTable does not scroll anymore. When looking in the logfile, I see the clock is still updated, the SQL method is still called and returns, but I do not anymore see the "ScrollUpdater is still alive" message!

I set the ScrollUpdater thread to MAX_PRIORITY, the other two to MIN_PRIORITY. How can this be???
There are no exception anywhere, so it's impossible the run() method exited, right?
Hope somebody has a good tip for me, as I'm really confused here

(by the way, normalSleep is 25 ms, longSleep is 100*25 ms)

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing is *not* thread safe !! You are not allowed to make changes to components, once it is running, in anything but the event dispatch thread.

Take a look at the invokeXXX() methods of the javax.swing.SwingUtilities class to get code to run in the even dispatching thread. Also.... be careful though. There is only one event dispatching thread, and it needs to manage the GUI. So only use it to run short lived code that changes the GUI.

Henry
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha!! Thanks. I'm going to try the following now:

 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, this particular case is a good candidate for javax.swing.Timer, which always runs its action on the Swing event thread.

The database query should always be on a separate thread, because it could block while waiting for a result, which would hang the GUI until it finished.
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey,
You are completely right. I read something about that in the meantime and that is the way to go. Anyways, this reminds me again that you have to be quite careful when using threads.
Thanks all (of you both for helping me out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!