|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
JMS Connection Pooling???????????????????? |
« View previous topic :: View next topic » |
Author |
Message
|
eswarnv |
Posted: Tue Apr 08, 2003 5:37 am Post subject: JMS Connection Pooling???????????????????? |
|
|
Voyager
Joined: 20 Dec 2001 Posts: 88
|
Hi,
I am using MQSeries 5.2 version server and MQSeries Java Client(ma88_win). I have few doubts regarding the connection pool,
1) Is there any default connection pool available If we are using MQJMS programming?
If yes how to use it? ( Want to have customized no of connections and timeout)
If no how to implement it?
2) What is the significance of "USECONNPOOL" property of QCF of admin command tool.
Thanks in Advance
Eswar. |
|
Back to top |
|
 |
sknrt1 |
Posted: Mon Apr 14, 2003 5:52 pm Post subject: |
|
|
Apprentice
Joined: 22 Jan 2003 Posts: 39 Location: USA
|
HI,
I have written a MQSessionPool appliction, which is very useful for me spanning no of threads accessing MQ and participating in transactions.
This sessionpool will act as active resourcepool.
Hope it will help u.
It consists of 2 classes
1.MQPooledQueueSession.java
2.SessionPool.java
--------------------------------------------
package com.cme.jms;
import javax.jms.*;
import com.ibm.mq.jms.MQQueueSession;
/**
*
*
* This class acts as a JMS Session pool for a particular JMS Connection. The JMS Session object has been
* subclasses into PooledSession.
*/
public class SessionPool
{
private int capacity;
private boolean QUITE;
private MQPooledQueueSession[] qSession;
private static final int NONE_AVAILABLE = -1;
/**
* This is the default constructor to create a session pool
* @param connection
* @param capacity
* @param transMode
* @param ackMode
*/
public SessionPool(QueueConnection connection, int capacity, boolean transMode, int ackMode)
throws JMSException
{
QUITE = false;
this.capacity = capacity;
qSession = new MQPooledQueueSession[capacity];
try {
for( int i=0; i<capacity; i++ )
{
MQQueueSession mqsession = ((MQQueueSession) connection.createQueueSession(transMode, ackMode));
qSession[i] = new MQPooledQueueSession(mqsession);
qSession[i].setInUse(false);
qSession[i].setPool(this);
}
}
catch( JMSException e )
{
for( int i=0; i<capacity; i++ )
{
if( qSession[i]!=null )
qSession[i].close();
}
throw(e);
}
}
/**
* Tries to get an instance of a session without blocking
* @return Session Null if no session is available, the session object otherwise.
*/
public MQPooledQueueSession getSessionNoBlock()
{
return reserve();
}
/**
* Returns the session object. If the session object is not available, this method blocks.
* @return Session
*/
public MQPooledQueueSession getSession(int _timeout)
{
while( !QUITE )
{
MQPooledQueueSession session = reserve();
if (session != null)
{
return session;
}
synchronized (this)
{
try {
wait(_timeout);
} catch( InterruptedException e ) {
}
}
return reserve();
}
return null;
}
/**
* This method performs the synchronized scan for an available session.
*/
private MQPooledQueueSession reserve()
{
synchronized(this)
{
int chosen = NONE_AVAILABLE;
for( int i=0; i<capacity; i++ )
{
if (!qSession[i].isInUse())
{
chosen = i;
break;
}
}
if( chosen != NONE_AVAILABLE )
{
qSession[chosen].setInUse(true);
return qSession[chosen];
}
return null;
}
}
/**
* This method is called by the PooledSession when it is returned to the pool.
* This notifies all the blocking threads that there is an available Session.
*/
void sessionAvailable()
{
synchronized(this)
{
notify();
}
}
/**
* Destroyes the session pool. All pooled sessions are closed.
*/
public void close()
{
QUITE = true;
for(int i=0; i<capacity; i++)
{
try {
qSession[i].getSession().close();
}
catch(JMSException e)
{
e.printStackTrace();
}
}
}
}
----------------------------------------------------------------
package com.cme.jms;
import com.ibm.mq.jms.MQQueueSession;
import com.ibm.mq.MQQueueManager;
import javax.jms.JMSException;
import com.cme.jms.SessionPool;
public class MQPooledQueueSession
{
private boolean pooled;
private boolean inuse;
private SessionPool pool;
private MQQueueSession session;
public MQPooledQueueSession(MQQueueSession _session)
{
inuse = false;
pooled = false;
session = _session;
}
public void close()
{
inuse = false;
}
public boolean isInUse()
{
return inuse;
}
public boolean isPooled()
{
return pooled;
}
public void setInUse(boolean value)
{
inuse = value;
}
public void setPool(SessionPool _pool)
{
pooled = true;
pool = _pool;
}
public MQQueueSession getSession()
{
return session;
}
public void setSession(MQQueueSession _session)
{
session = _session;
}
}
-----------------
thanks |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|