I am new JMS arena, I have created multiple message listeners but one listener per thread. I have following message listener, This message listner is passed a session object while it is constructed. Then when the message is received then this message listener processes message then commits the session as shown in the code. Closing sessions/connections is done in shutdown hook.
public class MyMessageListener implements MessageListener, ExceptionListener {
private Session _session = null;
public MyMessageListener(Session s) {
_session = s;
}
@Override
public void onMessage(Message arg0) {
try {
// Retrieve the data
JMSBytesMessage bytesMessage = (JMSBytesMessage) arg0;
byte[] payload = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(payload);
String payloadString = new String(payload);
ProcessMessage(payloadString);
_session.commit();
MessageCounter.Increment();
} catch (Exception e) {
e.printStackTrace();
}
}
public abstract void ProcessMessage(String theMessage);
}
Now my worry is that if listener receives two messages at the same time, will there be a chance the session commits both messages?