This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
You can implement it in the same way as any other application. But remember that you won't be able to return any value from servlet2 to the client as there won't be any output stream available to write to the client...
In servlet multithreading on request basis,
If two client call one servlet then container will start new two thread for two requests,
In your code,
Servlet 1
{
call servlet2.
redirect to another jsp page.
}
above quoted code is either forward or include...
in forward case, control is not returns it forworded to servlet2(here it will not redirect to jsp page)
when user call Servlet1 container starts thread1(suppose) when we forward to servlet2 container will call servlet2 and execute service method in thread2
In include case, it will call servlet2 and execute it all & write response of that servlet in Servlet1's response object that we passed to include method while including servlet2 and then redirect to jsp page.
when user call Servlet1 container starts thread1(suppose) when we include to servlet2 container will call servlet2 and execute service method in thread2 after that thread2 execution is completed with servlet2 service method and it returns to thread1 which is executing servlet1 service method.
Thanks,
Shailesh
Saurabh Agarwal
Greenhorn
Joined: Aug 27, 2007
Posts: 18
posted
0
Thanks Sailesh.
But problem with include is..
w will have to wait for servlet 2 to complete, then only response will be redirected to jsp page.
I cannot wait for servlet 2 to complete its execution. as it takes 30 minutes.
Is there some other way
Saurabh Agarwal
Greenhorn
Joined: Aug 27, 2007
Posts: 18
posted
0
Ankit Garg wrote:But remember that you won't be able to return any value from servlet2 to the client as there won't be any output stream available to write to the client...
I dont have to return anything to client.
but
Ankit Garg wrote:You can implement it in the same way as any other application
how to do it !
can you give some code idea for line 1 and line 2 of servlet1 below.
Servlet 1
{
Line 1: call servlet2.
Line 2: redirect to another jsp page.
}
Shailesh Narkhede
Ranch Hand
Joined: Jul 10, 2008
Posts: 356
posted
0
But problem with include is..
w will have to wait for servlet 2 to complete, then only response will be redirected to jsp page.
I cannot wait for servlet 2 to complete its execution. as it takes 30 minutes.
Is there some other way
that you can achieve by Thread class,
create one new class that extend Thread class and put all code in service of servlet 2 in the run() method of that new class,
and in service method of servlet2 create instance of thread class & call run() method on that instance.