aspose file tools
The moose likes Threads and Synchronization and the fly likes SwingUtilities.invokeLater in ActionEventHandler Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "SwingUtilities.invokeLater in ActionEventHandler" Watch "SwingUtilities.invokeLater in ActionEventHandler" New topic
Author

SwingUtilities.invokeLater in ActionEventHandler

smitham kumar
Greenhorn

Joined: Nov 08, 2006
Posts: 8
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
Marshal

Joined: Jul 08, 2003
Posts: 24049
    
  13

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.


[Jess in Action][AskingGoodQuestions]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16684
    
  19

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
smitham kumar
Greenhorn

Joined: Nov 08, 2006
Posts: 8
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

Joined: Nov 08, 2006
Posts: 8
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?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: SwingUtilities.invokeLater in ActionEventHandler
 
Similar Threads
Share parts of my choice.txt with javaranchers
Yes! Passed! 388/400
Will this locking mechanism be allowed?
My locking approach...comments please
Almost ready to hand up: Just cleaning up and have a few questions