• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create seperate Thread in servlets?

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please give some more extra details ....
So, that we can help you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic