Running Tomcat 6.0.18 Standalone on Windows XP.
I need a background task which I implemented as a thread that I stated
in the ContextListerner. In the contextInitilized() method I create and
started the background process. I give it a name and made it a daemon.
All that works great! The problem I noticed is that while I only call
the BackGroundThread.*start()* method once. I see at least two threads
running in Tomcat (las seen in Thread dump and looking at it in
"Probe"). I only instantiate one instance, but Tomcat behaves like it
is also calling start() again after I return out of the
ServerContextListener.contextInitialized() method. Now I can program my
background task to be thread safe and avoid conflicts with it's clones,
but it seems wasteful, and it causes a lot of lock friction. So my
question is, why do I see two threads running, when I only started one
and how can I avoid the duplicate thread?
Before you say why don't you run the task as a separate OS task, I am
managing a resource (RS232 serial line) that is owned and controlled by
my Tomcat application, so it must run inside Tomcat.