Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SwingUtilities.invokeLater in ActionEventHandler  RSS feed

 
smitham kumar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,


I have a application code that has GUI with a 'JButton' when this is clicked the actionperformed method creates another thread by using invokeLater(runnable)...

It is this thread that does the following

(1)--calls a method to do some calculation and then update the database by adding data to 2 different tables.

(2)--then refreshes the screen and dispalys the newly calculated values in other parts of the screen.

(3)--also shows a msg that all deeds where done properly!

Every thing works the way it has to (the way it has been told to) most of the time..

BUT......But...

there are times when the calculated value that is dispalyed on the screen and in its respective record in the table is 0.0 for one of the two values(always the second one) calculated.
But the date and time field of the same record which is stamped at the same time when the values are stamped--is just fine!(In theory if there is something wrong with the method coding or anything else even the date and time also teh first value should not have been updated properly)....

Any Help..any hint in this regard will be sincerely appreciated!

Thanking you all in advance....
Smitha
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea what your question is, really, but I will tell you that "invokeLater()" doesn't create a new Thread -- it runs the Runnable on the existing GUI thread.
 
Henry Wong
author
Sheriff
Posts: 22840
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed, the purpose of invokeLater() is to support threads, but it doesn't create any. Basically, you are supposed to create your own threads, either directly, or via the Timer or Executor classes.

Now, unfortunately, Swing isn't thread safe. It's components can't be accessed from the threads that you created. So... when these threads that you created needs to access the Swing components, you are suppose to use invokeAndWait() or invokeLater() methods, to execute the swing specific portions with the event dispatching thread.

Henry
 
smitham kumar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys for replying and correcting me....am new to Java world..
here is the code that I was talking about please let me know if there is any thing is going wrong...

In the code the method "updateWeightCollection" is what doing all the calulation(whic in turn calls several other methods to get the job done) and persistence to database. everything works fine when I test the code but there has been cases reported where in the data needed for the calculation is available but yet the result is 0.0 for one value

I really do appreciate all your help..


 
smitham kumar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code that I have posted...why in the first place the updateWeightcollection is being done in the "CalculateAndSaveThread" couldn't they have done it without it I mean call the "updateWeightcollection" from the sessionbeanremote directly in "actionPerformed" instead of going thor' the thread stuff?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!