Results 1 to 5 of 5
Thread: Servlet Multithreading
- 10-14-2009, 07:54 AM #1
Member
- Join Date
- Feb 2008
- Posts
- 6
- Rep Power
- 0
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
- 10-14-2009, 07:56 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
Factor the logic in servlet2 to it's own class which implements Runnable. You can then start that runnable from both servlet1 and servlet2.
- 10-14-2009, 08:04 AM #3
Member
- Join Date
- Feb 2008
- Posts
- 6
- Rep Power
- 0
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
- 10-14-2009, 08:31 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
No. Don't make your servlets implement Runnable. Create a separate class that implements runnable and start that thread in both servlet1 and servlet2.
- 10-18-2009, 05:13 AM #5
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 13
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).
Neil Coffey
Javamex - Java tutorials and performance info
Similar Threads
-
Which thread do the process first if we use multithreading ?
By cinjojose in forum Threads and SynchronizationReplies: 4Last Post: 10-12-2009, 11:23 AM -
Applet and multithreading
By pricelessjunk in forum Threads and SynchronizationReplies: 1Last Post: 08-03-2009, 09:47 PM -
multithreading
By shilpa.krishna in forum New To JavaReplies: 2Last Post: 06-27-2008, 04:18 PM
Bookmarks