Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do Listeners execute in seperate thread?

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listeners listen to an event. When we say an event in terms of application it is generally an independent happening. So do the listeners that listen to an event say "change in session attributes" execute in a separate thread.

Thanks in advance
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely Listeners execute in the Thread that generates the event.

Bill
 
Paul Clapham
Sheriff
Pie
Posts: 20770
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably all threads are "separate" -- that isn't a well-defined term. If you were asking whether they execute in a different thread, the question in response is "What thread did you have in mind that this thread was different from?"
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant every HTTPServletRequest executes in a separate thread so that different sessions are maintained. Now if i have a Listener that listens to session and executes the code segment whenever the session is modified then does this listener execute in the same thread as the HTTPServletRequest or a new thread is generated in which the Listener Code executes. I simple words is the processing synchronous or aSynchronous.

I hope you are getting what i am trying to say.
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shukla raghav wrote:I meant every HTTPServletRequest executes in a separate thread so that different sessions are maintained. Now if i have a Listener that listens to session and executes the code segment whenever the session is modified then does this listener execute in the same thread as the HTTPServletRequest or a new thread is generated in which the Listener Code executes. I simple words is the processing synchronous or aSynchronous.

I hope you are getting what i am trying to say.



Listener would run in the same thread as HttpServletRequest is being processed.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I think the threads execution may in synchronized way. for instance after creation a session it may start a new thread which execute sessionCreated method of HttpSessionListener.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you download the source code for Tomcat and examine how the various listeners work then?

I'm betting you will find that the Thread which generates an event executes all the listeners.

Bill
 
Paul Clapham
Sheriff
Pie
Posts: 20770
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would bet that too. As a user of the servlet container I would expect that if my servlet added a session attribute, then the listener would be notified of that immediately, before my servlet did anything else. I certainly wouldn't expect it to happen at some unpredictable later time. And I'm willing to bet (a smaller amount of money) that the servlet specification agrees with me, although I'm not the one interested in the answer so I'm not going to spend time looking it up.
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well till now i thought they are aSynchronous but now i believe they execute in the same thread as the HTTPServletRequest but still i will verify myself.

Thanks All
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic