Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading and Servlets: Best Practise  RSS feed

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello;

I have a few processes that get started in servlets in my application. In all cases the servlets instantiates a class which contain methods to manage the process required.

The problem I am finding is the application is starting to get slow from a user perspective while some of these processes are going on.

I have 2 questions:

1. What is the best practise to put these processes on their own threads? Is there a design pattern reccommended for starting threads in servlets?

2. Most of these processes don't need to run immediatly. Is there a schedueling system I could implement? Perhaps some sort of scheduler that starts up every few minutes and checks a queue listing what processes need to be done. Maybe there is a third party application that could handle this?

Thanks,

Luke
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. When I do this, I simply give the worker Thread the lowest priority. This should keep the web server running close to normal speed.
2. Having a single job scheduler that manages a queue of jobs sounds right to me.
Bill
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the topic of the job scheduler.

Is there anyway to create something independent of the web application (maybe a cron job that starts a job scheduler java thread)? This way if no one is using the web application this scheduler could be still be running. Is there any advantages to such an approach?

How is this normally done?

Thanks,

Luke
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your last reply. It is a design decision whether to use threads with servlet or not. I can tell that yes there are web application who creates threads.

For scheduling please have a look for how to use quartz scheduler.
[ July 25, 2005: Message edited by: Jignesh Patel ]
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! This is awesome. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!