• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Servlets and wait notify code

Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ahve a normal servlet,
so as per the client requests it is going to spawn new threads for service method.
and for some condition i want to have a wait and notify methods in the servlet.
Is that okay.
cos someone on my office was sayingt that it is not advisable to use wait and notify in service methods of servlets.
but as far as my knowledge is concerened, i feel that if i want to keep data consistent across multiple thread we have to use waut and notify.
can anyone throw some light on this
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet container is responsible for assigning a Thread to each request. Generally there is no reason for you to create your own Thread unless there is some job to be performed independently from handling a request.
The way you keep multiple requests (Threads) from interfering with each other is by NOT using any instance or static variables for data that changes between requests. Only use variables that are local to methods.
For variables that must be shared between requests, use the synchronized keyword to ensure that only one request (Thread) can use the variable at a time.
Any servlets book will discuss the problem in detail.
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic