wood burning stoves*
The moose likes Servlets and the fly likes Do Listeners execute in seperate thread? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Do Listeners execute in seperate thread?" Watch "Do Listeners execute in seperate thread?" New topic
Author

Do Listeners execute in seperate thread?

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
Surely Listeners execute in the Thread that generates the event.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 03, 2008
Posts: 200
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

Joined: Mar 18, 2010
Posts: 518
    
    2

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.


Regards
KumarRaja

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 03, 2008
Posts: 200
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do Listeners execute in seperate thread?
 
Similar Threads
I want implement a Swing/Hibernate application
Event overflow
Javacap mock test que-27
listener
Creating an event?