I am using a Message Driven Bean for storing messages in a list as you can see in the code given below:
/**
*
* @author sana-naeem
*/
@MessageDriven(mappedName = "jms/Queue-0", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MyMessageBean implements MessageListener{
private static ArrayList<String> list = new ArrayList<String>();
public MyMessageBean() {
}
@Override
public void onMessage(Message message) {
Textmessage msg = (TextMessage) message;
try {
if (message instanceof TextMessage) {
list.add("Messages: "+msg.getText());
} else {
System.out.println("No Text!!!");
}
} catch (JMSException ex) {
System.out.println("JMS.Exception....!!!");
}
}
public static ArrayList<String> getList() {
return list;
}
public void setList(ArrayList<String> list) {
this.list = new ArrayList<String>();
}
}
Now the problem is when I access the getter method from another Java Class; it is displaying list size=0;
Can I please know why is this happening;
I want to get that list in another Java Class;
If there is something wrong with the Queue, kindly let me know How to fix it???
It was working fine before;
Actually, previously I was using a Servlet to send messages but now, I am using a simple Java class with some initial context parameters defined...; so now the list is not working as expected...
Any advice or suggestion would be highly appreciable.
Thank you!