• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create seperate Thread in servlets?  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pallav Bora
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Gokul Nanthakumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prabhat Shankar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please give some more extra details ....
So, that we can help you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!