File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes How do I make one instance always available in Tomcat 3.3? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How do I make one instance always available in Tomcat 3.3?" Watch "How do I make one instance always available in Tomcat 3.3?" New topic
Author

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

Kevin Bolton
Greenhorn

Joined: Nov 20, 2001
Posts: 8
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?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kevin Bolton
Greenhorn

Joined: Nov 20, 2001
Posts: 8
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

Joined: Jun 25, 2001
Posts: 15629
    
  15

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I make one instance always available in Tomcat 3.3?
 
Similar Threads
Java in XSLT
Automated mail from the recepient
implementing email relay
Help understanding when to use em.find and query manager and their ability to fetch nested objects
Updating bean object through servlet