thonnor
thonnor

Reputation: 1246

Java Servlet to start & monitor a polling process

I have a Web app that contains a polling process (infinite while loop) that is started up by a Servlet when the Tomcat service starts up.

<load-on-startup>0</load-on-startup>

Which works fine.

If this were a Unix process then I could check it on the command line using:

ps -ef | grep <myProcess>

Is there anything (simple) that can be used in a Servlet to monitor the status of my Polling process?

EDIT

To clarify, all I really want to see is that the process is still running and hasn't stopped.

Upvotes: 0

Views: 898

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148965

IMHO, you should not use a Servlet for that use case, but a ServletContextListener. In its contextInitialized(ServletContextEvent sce), the listener should :

  • start the polling service thread
  • put in a ServletContext attribute an object containing state (last operation date, number of operation per ...) from the polling thread (and having a synchronization mechanizme)

Then, the listener could stop the polling thread in its contextDestroyed(ServletContextEvent sce), and any servlet (including JSPs) could get the state of the polling thread from the ServletContext.

Upvotes: 1

Related Questions