连接失败:达到最大连接数0

时间:2014-01-06 15:23:25

标签: jms tibco tibco-ems

max_connections 属性设置为 0 (无限数量的连接)但仍然是ems服务器继续将其吐出到tibemsd.log

[admin:somehost]:连接失败:达到最大连接数0

这怎么可能?

谢谢!

2 个答案:

答案 0 :(得分:0)

对于任何有兴趣的人,

似乎最多256个管理连接的限制可以同时打开到ems服务器。 由于某种原因,此限制显然不受 max_connections 属性控制。

这是一个验证这一点的小例子。

import com.tibco.tibjms.admin.TibjmsAdmin;
public class AdminConnectionTest{
 public static void main(String args[}){
  int counter =0;
  try{  
   for(int i=0;i<1000;i++){
   TibjmsAdmin admin = new TibjmsAdmin("tcp://localhost:7222","someuser","someuser");
   counter++;
   }

  }catch(Exception e){
   System.out.println( "Connections created: "+counter);
   System.out.println( e.getMessage());
   try{
    Thread.sleep(20000); //Some delay to make it possible to verify this from emsadmin
   }catch(Exception ee){System.out.println( ee.getMessage());}
  }
 }
}

答案 1 :(得分:0)

为了防止客户端通过连接重载服务器,我编写了一个简单的commons pool2类。

import com.tibco.tibjms.admin.TibjmsAdmin;
import com.tibco.tibjms.admin.TibjmsAdminException;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class TibcoAdminPoolableObjectFactory implements PooledObjectFactory<TibjmsAdmin>{
    @Override
    public PooledObject<TibjmsAdmin> makeObject() throws Exception {
        TibjmsAdmin admin = new TibjmsAdmin("tcp://tibco:7222","USER","password");
        return new DefaultPooledObject<>(admin);
    }
    @Override
    public void destroyObject(PooledObject<TibjmsAdmin> po) throws Exception {
        po.getObject().close();
    }
    @Override
    public boolean validateObject(PooledObject<TibjmsAdmin> po) {
        try {
            po.getObject().getQueue("xyzabc");
        } catch (TibjmsAdminException ex) {
            System.out.println(ex.getMessage());
            return false;
        }
        return true;
    }
    @Override
    public void activateObject(PooledObject<TibjmsAdmin> po) throws Exception {}
    @Override
    public void passivateObject(PooledObject<TibjmsAdmin> po) throws Exception {}
}

GenericObjectPool<TibjmsAdmin> pool = new GenericObjectPool<>(new TibcoAdminPoolableObjectFactory());
TibjmsAdmin admin = pool.borrowObject();
QueueInfo infos[] = admin.getQueues("YOURQUEUE");
pool.returnObject(admin);//in a finally block