• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listener instance and Thread safety

 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Could you tell me whether the listener instance are thread safe or not? Whether one/more instance are created for a particular listener configured in web.xml?
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tridib Samanta,

Listeners are interfaces. so there wont be listener objects.

We will implement listeners in a class.
example: HttpSerlvet implements HttpSessoinListener.

thread-safety for listener code:

When you say My servlet or Jsp is thread safe. it involves all members and methods(listeners implemenation too--> implicit).

Any method in servlet can access instance variables, applicationContext,Session... etc.

So we are responsible to make a servlet or JSP theradsafe.

Another important point:
Listener method implementations are called by container not by us. So we can not apply high level locks on method calls. so we have to be carefull with listener implementation methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic