aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Message Driven Servlet Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Message Driven Servlet Problem" Watch "Message Driven Servlet Problem" New topic
Author

Message Driven Servlet Problem

Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
I have made Servlet with Message listener (I do not require MDB for that so no question why i am using servlet).

The code is following:



* in output i get Results

1) When i run servlet firstly then it showed proper output. Then if i will remove following code:
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException ex) {
Logger.getLogger(MessageConsumer.class.getName()).log(Level.SEVERE, null, ex);
}

then also it will show output correctly

2) When i change destinationname:
@Resource(mappedName = "jms/tConnectionFactoryTopic")
private ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/MyTopic")
private Topic topic;
t is giving Messages for previous entries.

3) When i redeploy it and add Thread.Sleep then it will show messages for MyTopic

4) When i redeploy the Message Driven Servlet then too it does not show messages which were send during deploying

.
.
.

Kindly tell me how to manage all this properly without any Error.


Regards
Azrael Noor
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 515
Hello there,
Even if you do not want to use MDB you can use POJO that implements the MessageListener than servlet.
Servlet is not a very good fit because you need to hit the servlet to start your listener.
Also you should not fiddle with Threads inside the Servlet as it is already multi-threaded. That might be the reason you are seeing the behaviour you are explaining.
Hence even if you use a servlet, do not make attempt to sleep the thread or anything like that. By the way can you please let us know why you want to call Thread.sleep().

Regards,
Amit
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Hello

Actually i need to handle multiple annotations which is not possible in single mdb.
i tried to do it through servlet.

I haven't studied POJO, thanks for telling that let me see wether it works.

I used thread.sleep because
when i hit servlet and it runs and does not listen to message.

I make servlet sleep first time, then it listen messages,
but after using first time if i remove thread.sleep
then it works fine(recieve messages without sleep)
but take entries of 1 connection factory only,
not work fine for multiple connection factories in single servlet. So Servlet and MDB both are not solving ma problem efficiently

let's see what POGO is. If you have any better solution do tell

Thank you for Replying
Azrael Noor
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
No Need of It now.

Thank you, if anyone could add more information please
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Message Driven Servlet Problem