1 Reply Latest reply on Oct 22, 2001 12:03 AM by Aaron Smith

    servlets+thread

    raja Newbie

      Scenario:
      We have an action that needs to be initiated by a servlet, but will
      Take some time to accomplish and so the servlet should just hand it off to a
      separate thread for actual processing, and the servlet should just
      respond immediately with a redirect to a JSP page that outputs a simple
      message saying the action has been initiated and current date and time.

      Task:
      So, create a servlet that accepts a parameter in the request (both POST
      and GET requests should be supported) and set up a separate worker
      thread (set one up in the init() method of the servlet) that it will
      hand off requests to. The servlet will call into the worker thread
      passing it the parameter value which will be put on the worker thread's
      queue.

      The worker thread should stay asleep until it receives requests. Any
      requests will wake up the worker thread which will then process it's
      queue. The action would be a long running process, but for this test,
      it
      will just be to log a message to System.out including the parameter
      value and the current timestamp.
      if posssible please tell me the code/b]

        • 1. Re: servlets+thread
          Aaron Smith Newbie

          The biggest problem I see with your proposal is that you shouldn't create your own threads. Threads should be created and managed by the Web Container only, of which you have no real direct control.

          You haven't said what action needs to be taken when the process has finished, so I will assume that the user does not need to be automatically redirected to view the results (ie: they could log on later and find the results in a list, for example).

          In this case, you are talking about asynchronous processing, so I would suggest you generate a JMS message, and write a Message Driven Bean to perform the processing.

          Hope this helps,
          Aaron.