• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

SwingUtilities.invokeLater problem

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi frenz.. i m making an application in which I m calling servlets from Swing applications. these servlets are talking to database and performing some operations. so far fine.
these opeartions are time consuming.. so I thought of using SwingUtilities. invokelater(). but I want to get return values from these operations which will be taking place in runnable objects run method. compiler is saying these values should be final. but i want to use these values in other parts of the programs.
i.e. after servlet is done with its work.. it returns a value... I want to work with that value...plz help if anybody have any idea. plz make sure reply is easy to understand coz i m not perfect.
thanx
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try making the local variables you want to access in the inner class instance variables of the outer class.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take care : using SwingUtilities.invokeLater will cause your code to be executed on the event dispatching thread, I think it will be better if you create your on Thread...

I'm not sure to understand your needs concerning the objects that you want to deal with after your thread return, but maybe you should have a look on the consumer / producer sample in the Java tutoriel (Threads section)
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As someone already said, look at the Threads page

There is a link on the page to the useful SwingWorker class
http://java.sun.com/docs/books/tutorial/uiswing/misc/example-1dot4/SwingWorker.java
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also create a version of your variables for the new Thread to play with. For example:



If you want to actually modify a variable in your new Thread, then use it later in the mehod you started that Thread from it's another story, especially if you need the new Thread to complete it's task before you do. In your case it may be more appropriate to have a callback. For example:

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic