0
votes

I'm working on stand-alone multi-threaded application , where am using plain JMS API's to send and receive messages synchronously using P2P mechanism. When multiple threads are running , exception is thrown while recieving the data using consumer object(one consumer object per thread) saying IllegalStateException: Session is closed. I tried in below two ways.

1)Created connection and session objects in a singleton class and using those objects while sending and receiving the messages. Synchronized the piece of code that sends and receives the messages.

2) Created the SessionPool class(singleton) where it creates 5 sessions. As My application is limited to thread pool count 20 and each thread retrieves the session from sessionpool and returns session back once the message is received. This worked fine for 5 threads and later throwed exception saying session is closed.

Please help me on how to use effectively use session objects with out creating one session per one thread.

1

1 Answers

0
votes

You might want to reconsider your architecture.

JMS is a way to communicate between JMS provider and JMS consumer[s]. This is more of a client-server architecture. I would not recommend using that for p2p.