Win a copy of Design for the Mind this week in the Design 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()";
log.info("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);
log.info("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()";
log.info("Entering : " + location);
log.debug("PMTCProperties.getProperty(JMS_FACTORY)==="+PMTCProperties.getProperty("JMS_FACTORY"));
log.debug("PMTCProperties.getProperty(JMS_FACTORY)==="+PMTCProperties.getProperty("FAS_JMS_FACTORY"));
//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();
log.info("Exiting :" + location);
}



Could some one guide me how to avoid this?

Thanks in advance

Manish
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic