java - file listener process on tomcat -
I need a very simple process that listens on a directory and when something new is created on that directory Operates. / P>
I think I need a thread pool.
It is very easy to use the spring structure, which I normally use but now I can not use it. I can only use Tomcat, how can I implement it? What is the entry point that "starts" thread?
Thanks
Since you refined the question Here's another answer: How to start a daemon in Tomcat:
First, register your daemons in the web. Xml:
& lt; Audience> my.package.servlet.Demons & lt; /
This code will be called every 5 seconds, when the Talkcat reference will stop when your app stops, note that the variable is variable, otherwise you may have trouble on the shutdown of the multi-core system
import javax.servlet.ServletContextEvent; Import javax.servlet.ServletContextListener; Public Class Demon's Sententacentex Listener {Personal Volatile Boolean Active = True; Runnable myDeamon = New Runnabal () {Public runs zero () {while (active) {try {System.out.println ("Check changed files ..."); Thread.Sleep (5000); } Grip (Interrupted e) e.printStackTrace (); }}}}; Public Zero Concept Begins (ServletContextEvent servletContextEvent) {New thread (myDeamon) Start (); } Public Zero was referenced (SerialContactEventServalConttexEvent) {active = false; }}
Comments
Post a Comment