Discussions

Web tier: servlets, JSP, Web frameworks: thread with in the servlet..?

  1. thread with in the servlet..? (2 messages)

    import javax.servlet.*; import javax.servlet.http.*; public class NewProcess extends HttpServlet implements Runnable { HttpServletRequest request; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.request = request; Thread up = new Thread(); up.start(); } public void run() { /*here i want to use request object . is it posible*/ } } my problem is i star the thread.. But it will not come to the run method... Give me your comments
  2. Re: thread with in the servlet..?[ Go to top ]

    The servlet container provides concurrency service to the servlet. There is normally no need to make a servlet runnable. It is an antipattern to use threading in servlet code. Your intention of using run is not clear. Every invocation of this servlet will cause a thread to be created. You are not able to execute run here because you have not provided the Thread object with the runnable handle. You can achieve your intended purpose with the following modification Thread up = new Thread(this);
  3. Re: thread with in the servlet..?[ Go to top ]

    I have seen new developers and transfer ASP developers do this in the past. This is just a question you should ask.. Why are you trying to create a thread? The Servlet API is concurrent complaint, and as long as you do not create instance variables, you need not worry about this. So this is an anti-pattern. HINT: If you wish for a service to run asynchronously, I would suggest using JMS functionality or JMS to message Drive Beans (MDB) if you are in a full J2EE JEE environment, which better suits this model, and performs better due to pooling. I cannot for see why you would need code to do this, and may conflict with the underlining code of the Servlet container ( Depending who the source of the container, and how they implemented their concurrency code) if you still have this issue, and must use Threads in the Servlet, re-post and I will at least think of a solution. Tony McClay