Results 1 to 5 of 5
  1. #1
    Saurabh321 is offline Member
    Join Date
    Feb 2008
    Posts
    6
    Rep Power
    0

    Default Servlet Multithreading

    Hi

    I have to implement below scenario :

    Servlet 1
    {
    call servlet2.
    redirect to another jsp page.
    }

    In above code segment, servlet2 must execute in background.
    And control must immediately be redirected to jsp page without waiting for servlet 2 to complete.
    Normally this can be implemented using threading.

    But how will threading be implemented in servlets.

    Thanks

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Factor the logic in servlet2 to it's own class which implements Runnable. You can then start that runnable from both servlet1 and servlet2.

  3. #3
    Saurabh321 is offline Member
    Join Date
    Feb 2008
    Posts
    6
    Rep Power
    0

    Default

    Thanks..

    This means I should implement runnable interface in servlet2. and then start it from servlet1. For this i will have to create object of servlet2 in servlet1.

    Please comment if I am wrong

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    No. Don't make your servlets implement Runnable. Create a separate class that implements runnable and start that thread in both servlet1 and servlet2.

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Within reason, you can start threads from a servlet just as from any application. And as with any application, consider using something like the Executors framework to manage your background tasks (link is to some info I've written in case helpful).

Similar Threads

  1. Which thread do the process first if we use multithreading ?
    By cinjojose in forum Threads and Synchronization
    Replies: 4
    Last Post: 10-12-2009, 11:23 AM
  2. Applet and multithreading
    By pricelessjunk in forum Threads and Synchronization
    Replies: 1
    Last Post: 08-03-2009, 09:47 PM
  3. multithreading
    By shilpa.krishna in forum New To Java
    Replies: 2
    Last Post: 06-27-2008, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •