Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet spawning a new thread problem

843841Jan 22 2004 — edited Jan 23 2004
Hi

Here is a snippet of some simple code. Basically, the servlet creates a new thread, starts it, then continues and echoes back to the screen "BPD Running". I've not included the other classes, as they aren't relevant at the moment. Also, note this is a very simple servlet that I'm playing with to get a handle on how servlets/threads can be used together. I'm looking at spawning several threads in a later project, that need to be kicked off from a web invocation, hence the servlet.

What I can see from debug output is that the BPDThread is created and runs correctly, fulfilling its own task correctly. The problem is that on a subsequent page request to the same servlet, the servlet hangs, and Tomcat locks up.

I've noted that by stepping through on debug, on the SECOND request, when I get to bpd.start(), the system locks up.
public class ThreadPollServlet extends HttpServlet {
	
    public void doGet (HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
    {
		
		SearchBean searchBean = new SearchBean();
		searchBean.setEmsId("7024");
		searchBean.setSwiftId("65452");
		BPDThread bpd = new BPDThread(searchBean);		
		bpd.start();
		
        res.setContentType("text/html");
        ServletOutputStream out = res.getOutputStream();
        out.println("<html>");
        out.println("<head><title>BPD Process running in background</title></head>");
        out.println("<body>");
        out.println("<h1>BPD Running</h1>");
        out.println("</body></html>");
    }
}
Any ideas?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2004
Added on Jan 22 2004
3 comments
55 views