Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Scheduled Task

 
Ranch Hand
Posts: 281
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a requirement to launch a single instance of a task to run in the background in a continous loop. i.e I only want it to stop when I tell it to. The task will continually poll a message queue for data and process it when found. I guess therefore I don't want a timer task. I need to be able to check that the task is not already running in another thread and hence prevent a second thread from running. Some static variable flag ? I also need some way of requesting a gracefull shutdown of this single thread. I'm assuming that having only one instance (for want of a better term) of this thread running I will minimise thread safety issues - although that's not why I want only one instance running. Will it be possible for this thread to update a swing gui object (list or table) while it's running so there will be some indication of progress ?

If anyone has done this sort of thing (I'm using java 6) and has a simple example it would be great. Googling comes back with too many hits and it's confusing me !

Thanks

Dave
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you might want to look at the Java 6 SwingWorker. This class provides methods to safely start a background thread from Swing, to send data and progress notifications back to the Swing thread, and to interrupt the background thread to tell it to finish, and it can only be started once.

(Note that there are other, older versions of SwingWorker that are quite different, but that will come up in search results.)
 
David Garratt
Ranch Hand
Posts: 281
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip, I'd not come across that before.

Much appreciated.

Dave
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic