My application has JMS performance issue, by EOD we run into out of connection
The reason why i asked whether you are closing the connection, was based on what you mentioned in your first. You said that you run out of connections - which might be because you are not closing the connection after you send the messages.
My emphasis was on reusing the below code.
And going by what you mentioned in your second post, i am a bit confused. 1) Are you trying to refactor the code to reuse that piece of code? 2) Or are you trying to fix an issue where you are running out of connections?