David.Meldrum wrote:
> 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

Why not override the start method of your thread and drop a stack trace
and log message each time it's called? E.g.

some.log(Thread.currentThread().getName() + " in " +
servletContext.getContextPath() + " Stacktrace:");
new Throwable().printStackTrace();

You might even throw in an AtomicInteger count to see if how many
attempts to start are occuring.

p


> 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.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to