You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael McElligott <mi...@liquidplanet.com> on 2001/04/05 07:45:29 UTC

spawning new thread in context listener - tomcat never finishes initializing?

Here's what I've got:

win98
jakarta-tomcat-4.0-b3.zip uncompressed into c:\tomcat4

I've added a listener in my web.xml document to listen for context initialization.  It's a copy of the listener provided in the examples app, with empty methods for everything except: 
    contextInitialized(ServletContextEvent event).  

In that method, I do a bunch of queries, plug some values into the application using setAttribute() and spawn a background thread that does some networking stuff on it's own timeline with the following code:

   if (blnWebAppDownloads)
   {
    Thread t = new Thread(new com.imageharvester.net.HarvestMaster());
    t.start();
   }

The problem here is this: Tomcat (and, from the looks of it, Apache) won't serve anything now, although the background thread appears to be running just fine and doing The Right Thing.

This may be of some help: I used to have this initialization code in my index.jsp file (which would run it the first time the page was accessed).  Ever since I added the code that spawned the new thread to that index.jsp file, even though the new thread starts running just fine, the html results of the page were never returned to my browser.  A subsequent request to the page ran fine (I assume this was actually another thread running that servlet and that the initial thread was still hung).

I read in earlier posts that spawning a new thread from the web application was okay (with some disclaimers about possible security manager problems).  I haven't changed any of the default configurations, so it can't be that.  Any ideas?

TIA,

Mike