Forums Register Login

How to create seperate Thread in servlets?

+Pie Number of slices to send: Send
Dear All,

I had my servlet which is given below



As per the above code i'm calling Template.exe which will perform some critical functions..... here in some situations the exe will take more time because the exe data processing will be more and as it is calling in the current thread the session is getting lost.so i want to call that exe in separate thread so it will run in back round.shall i create the separate thread in this servlet like


Please give me hand...

+Pie Number of slices to send: Send
I am not very clear about your query.

Actually when you are creating separate process (from your parent thread or child thread) using runtime1.exec(...). Now if you want to read the response of the process, you can get its output stream and keep reading it until it reaches to end. Now if you don't want to block the main thread while doing so, you can perform this operation in the child thread.

HTH
+Pie Number of slices to send: Send
If your infrastructure supports it then you can use an MDB. In case of WAS you don't even need an MQ installation as WAS itself comes with java messaging framework .
+Pie Number of slices to send: Send
Even if you create new thread also, the main thread will wait for the completion of the new child thread. so if you start new thread from servlet, it will behave same as calling the process directly. MDB is one option for this problem, or you can try quartz jobs, or you can have a standalone program which will execute this process and your servlet can just inform the program to execute the process.
+Pie Number of slices to send: Send
Hi,

Please give some more extra details ....
So, that we can help you.
Nothing? Or something? Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3154 times.
Similar Threads
Servlets example
HTTP method POST is not supported by this url
Methods in Servlet
Auto generate link for newly registered user
Servlet to servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:06:51.