• Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping track of Threads in JSP

 
Naadir Peterson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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!!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!