Starting thread inside servlets

Discussions

Web tier: servlets, JSP, Web frameworks: Starting thread inside servlets

  1. Starting thread inside servlets (2 messages)

    Hi all,
    does anybody know if starting a new thread (in order to perform time expensive operations) inside a servlet o a portlet can cause problems ?

    Thanks

    Davide
  2. Starting thread inside servlets[ Go to top ]

    For the most part, no. The only possible issue is that your security context may not propogate correctly for operations performed inside the thread. This will probably only be an issue if your servlet invokes an EJB, and expects the web authentication information to propogate to the EJB layer.

    Otherwise, you are probably safe.
  3. Starting thread inside servlets[ Go to top ]

    I don't think so, and I know the old version of the server at my previous company did it. But, it is considered bad programming style. If you have servlet container, then he manages the threads, not you. Also, it is not very scalable. I'd suggest using one of the two:
    * Use thread pool
    * Use JMS for asynchronous tasks

    David