This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes JMS - Listener as inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JMS - Listener as inner class" Watch "JMS - Listener as inner class" New topic

JMS - Listener as inner class

wai yuan

Joined: Dec 30, 2005
Posts: 9
I am trying to understand this (the code is working):

A QueueReceiver Wrapper class JMSReceiver has a inner class JMSListenerInstance which acts like a Listener. In the source code, JMSListenerInstance has 2 constructors:


The first constructor is empty, the second does something as following:

myQSession = (QueueSession)getJMSConnection().createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
Queue responseQueue = myQSession.createQueue(myQName);
QueueReceiver myQReceiver = myQSession.createReceiver(responseQueue);

*getJMSConnection is JMSReceiver method, basically just return a established connection.

And the JMSReceiver setup the listener by calling the first constructor

new JMSListenerInstance()

but not the second one. I would have thought the code is wrong if I don't know the code is actually working.

After compiling this code and look at it through eclipse. The 2 constructors become:

JMSListenerInstance(JMSReceiver, int)

So does the compiler do something to actually make this code work?
wai yuan

Joined: Dec 30, 2005
Posts: 9
Never mind.
This empty Listener actually is put into a object pool. And the pool manager calls the listener's function newInstance(). And this function creates a new listener by using the second constructor.
Don't get me started about those stupid light bulbs.
subject: JMS - Listener as inner class
Similar Threads
super & this
Error deserializing Object
Constructor Methods
Why constructors are not inherited by child class