• 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

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

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic