File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Resuse JMS Connection factory and jms Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Resuse JMS Connection factory and jms Connection" Watch "Resuse JMS Connection factory and jms Connection" New topic

Resuse JMS Connection factory and jms Connection

manish gupta
Ranch Hand

Joined: Nov 06, 2005
Posts: 36
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

I agree. Here's the link:
subject: Resuse JMS Connection factory and jms Connection
It's not a secret anymore!