• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keeping track of Threads in JSP

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am creating a JSP project, and one of my JavaBeans uses a thread that executes every hour to keep track of a Call Center's Orders for Auto Escalation. I want to be able to keep track of this thread on the server. Each time someone logs in to the site, the jsp should check that the Thread is running, if not a new instance should be created and the Thread started. What i currently have, is, a session is created with an instance of the Bean, this session is used to check that a new Instance of the Thread is not created each time the user visits the login page. However, if the session is terminated, a new Instance is created and at the end of the day i'm left with shit loads of auto escalating happening!! Is there a way of making sure that only one instance of the Thread is running at any one time. The thread should run constantly on the server and only terminate when an Exception is thrown or the sever shut down.

Hope you understand my explanation!!!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As much as we caution against the dangers of Singleton down in the OO, UML, etc forum, this sounds like a good application. A singleton class does two things: assures there is only one instance (or a tightly controlled number) and provides access to that instance. An easy implementation is:

As soon as any class references MyClass the static instance is created. And anybody can get access through the getInstance method.

DO visit the OO, UML, etc. forum and scan for discussions about the dangers of singleton. It's not something to be done too lightly. Cheers!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic