【问题标题】:connect failed: reached maximum number of connections 0连接失败:达到最大连接数 0
【发布时间】:2014-11-14 16:01:14
【问题描述】:

ma​​x_connections 属性设置为 0(连接数不限),但 ems 服务器仍不断将其输出到 tibemsd.log

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

这怎么可能?

谢谢!

【问题讨论】:

  • 听起来像是 Tibco EMS 试图保护自己。您是否尝试过使用公共池的连接池?

标签: jms tibco tibco-ems


【解决方案1】:

对于任何有兴趣的人,

似乎有最多 256 个管理员连接的限制,可以同时打开到 ems 服务器。 由于某种原因,这个限制显然不受 ma​​x_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());}
  }
 }
}

【讨论】:

    【解决方案2】:

    为了防止客户端的连接过载,我编写了一个简单的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多