Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we use ThreadPoolExecutor inside mothod doPost to increase the performance?  RSS feed

 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have used ThreadPoolExecutor class and i created 30 thread pool and i used inside post method..is it really needed or container itself handle multiple thread at a time.....please suggest me
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the servlet container is required to control the threads accessing the servlets.
In some cases it is beneficial or even necessary to do some thread management further down, but as a general rule never in the servlet itself.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container creates a new thread for each request that you fire from your browser. There is no need to code that yourself
 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have doubt please clear..

we have two thread model

single thread model
normal servlet that accept conncurent running....

in a single thread model each and every client request the container will create new thread or it maintaing thread pool
that is ok.

in normal servlet when client calls it will call service mothod..this service method concurrently executed by multiple threat..here is my doubt....when service method executed each and every thread will get its own object of servlet or single servlet with same service method...of single instance mean...how servlet responce to different client....suppose there is the chance two thread enter into service method and suppose i am authenticate thread 1 at the same time the username has changed by thread 2 means everything will fail..please answe my question

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SingleThreadModel is deprecated and should not be used.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaleeswaran Karuppasamy wrote:in normal servlet when client calls it will call service mothod..this service method concurrently executed by multiple threat..here is my doubt....when service method executed each and every thread will get its own object of servlet or single servlet with same service method...of single instance mean...how servlet responce to different client....suppose there is the chance two thread enter into service method and suppose i am authenticate thread 1 at the same time the username has changed by thread 2 means everything will fail..please answe my question


There will be a single instance of the Servlet, and all requests will share this single instance while using its own Thread.
Because of this, it is important that SErvlets do not maintain their own (instance or static) state as this will be visible to all threads and shared between them, possibly allowing one thread to read or overwrite data from another request. This is bad.
Variables in methods are safe, as there is a separate copy of the variable for each thread.

In your case I believe it is sufficient to make sure you avoid storing state in the servlet.

/Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!