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?
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.
Joined: Nov 20, 2001
How do I get a handle to the Fax Monitor null servlet from the doGet method of the servlet that sends the fax?
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.