Spawning multiple threads that monitor different files in a servlet
I am trying to spawn multiple threads that monitor different log files. So
basically user types in the host and path of log file to tail, then hits
the montior button which will then start a thread and initiate the
tailing. My problem is that I know threads are not supposed to be spawned
in a servlet as it would cause tomcat to complain about resources. The
other thing is I need to be able to stop tailing of the file whenever the
user decides to stop monitoring button. My first approach was to have a
map that takes in the thread and starts tailing of file, then whenever I
hit stop monitoring file then I get thread by key then call a method
stopThread which I flag a volatile attribute in and set it to false then
it stops. Is there a way which I can do it maybe using ExecutorService and
make the thread run without halting the program as I understand that
Callable will wait for results to return which in my case I don't want
halting. Any shed of ligh is highly appreciated. Thank you in advance.
No comments:
Post a Comment