• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How do I make one instance always available in Tomcat 3.3?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP page that allows the users to send a fax (scheduled and processed on another machine). The users want an email confirmation when their fax is done. So, when the user submits at fax, I give the fax to a FaxMonitor class that periodically checks the fax's status. When it is done, it sends an email to the user.
The FaxMonitor is Runnable and presently expects external code to put it in a Thread and start it. This could be changed to where it's constructor could do this.
I would like there to be one and only one instance of the FaxMonitor. It should be created either on startup or on first use. Once created, it should hang around virtually forever.
I'd like the one instance to be in the same JVM as the servlets so that I don't need to Serialize/Remote my code.
How should I do this?
 
Saloon Keeper
Posts: 26534
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like something I call a "null servlet". Just implement a servlet without a doGet/doPost and spawn the fax monitor thread from the servlet's init() method.
Or for what you want, you could even do that from the servlet that dispatches the fax. That way the doXXX() method could invoke a private synchronized method to the faxing process to kick off the job.
 
Kevin Bolton
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I get a handle to the Fax Monitor null servlet from the doGet method of the servlet that sends the fax?
 
Tim Holloway
Saloon Keeper
Posts: 26534
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you actually use 2 servlets, just pass the object(s) from servlet to servlet using the application context.
Though like I said, if you have a servlet actively doing the fax prep, you can start the fax monitor thread in that servlet's init() method, instead, if you prefer.
I use a "null servlet" mostly for non-transaction-dependent services like setting up database pools.
reply
    Bookmark Topic Watch Topic
  • New Topic