Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resuse JMS Connection factory and jms Connection

manish gupta
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created single MDB for processing all messages but for every messages it intialises all JMS resources every time.
I want to reuse all JMS resources .

my Existing code is

public InitialContext getInitialContext()
throws NamingException, Exception
String location = CLASS_NAME + ".getInitialContext()";"Entering : " + location);

String initialCtx = PMTCProperties.getProperty("FAS_INI_CTC_FACT");
String providerURL = PMTCProperties.getProperty("FAS_URL");

prop.put(Context.INITIAL_CONTEXT_FACTORY, initialCtx);
prop.put(Context.PROVIDER_URL, providerURL);
Context ctx = new InitialContext(prop);
Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, initialCtx);"Exiting :" + location);
return new InitialContext(env);

* Creates all the necessary objects for sending messages to a JMS queue.
* @param ctxJNDI initial context
* @paramqueueNamename of queue
* @exception NamingException if operation cannot be performed
* @exception JMSException if JMS fails to initialize due to internal error
public void init(Context ctx, String queueName)
throws NamingException, JMSException ,Exception
String location = CLASS_NAME + ".init()";"Entering : " + location);
//qconFactory = (QueueConnectionFactory) ctx.lookup(PMTCProperties.getProperty("JMS_FACTORY"));
qconFactory = (QueueConnectionFactory) ctx.lookup(PMTCProperties.getProperty("FAS_JMS_FACTORY"));
qcon = qconFactory.createQueueConnection();
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queuereceive = (Queue) ctx.lookup(queueName);
qsender = qsession.createSender(queuereceive);
msg = qsession.createTextMessage();
qcon.start();"Exiting :" + location);

Could some one guide me how to avoid this?

Thanks in advance

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic