Try setting up the JMS resources before sending the message, in a method annotated with PostConstruct.
@PostConstruct
public void init() {
// JMS Connection, Session, MessageProducer setup here
}
The method will be called when the class is instantiated and you can use the same connection for all messages while the bean is instantiated. Create another method annotated with @PreDestroy to close the resources before the bean is returned to the bean pool. After you send a message, call the method annotated with @PreDestroy to close the connection on your side.
That's the only way I've been able to overcome my JMS problems. I was sending 10K messages very quickly, opening and closing connections each time. The connections aren't returned to the pool fast enough by GlassFish for whatever reason. Your other option is to change setting in GlassFish on your connection pools (more connections).
Hope that helps.
[Message sent by forum member 'mtbittle' (mtbittle)]
http://forums.java.net/jive/thread.jspa?messageID=268625