JMS 池分配问题

发布于 2024-12-10 05:29:50 字数 5800 浏览 0 评论 0原文

我有一个 JMS 应用程序(使用玻璃鱼),可以在本地主机上完美运行。部署到我的服务器后,我在第一次调用服务时不断收到以下堆栈跟踪。

#|2011-10-14T22:22:51.927+0400|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors|_ThreadID=9342;_ThreadName=Thread-1;|RAR5117 : Failed to obtain/create connection from connection pool [ jms/MyConnectionFactor ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException|#]

[#|2011-10-14T22:22:51.928+0400|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=9342;_ThreadName=Thread-1;|com.sun.messaging.jms.JMSException: MQRA:DCF:allocation failure:createConnection:Error in allocating a connection. Cause: null
    at com.sun.messaging.jms.ra.DirectConnectionFactory._allocateConnection(DirectConnectionFactory.java:548)
    at com.sun.messaging.jms.ra.DirectConnectionFactory.createQueueConnection(DirectConnectionFactory.java:322)
    at com.sun.messaging.jms.ra.DirectConnectionFactory.createQueueConnection(DirectConnectionFactory.java:299)
    at com.clox.web.boot.ReadOfflineMessage.run(ReadOfflineMessage.java:67)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: null
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:310)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
    at com.sun.messaging.jms.ra.DirectConnectionFactory._allocateConnection(DirectConnectionFactory.java:543)
    ... 4 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException
    at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:103)
    at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1497)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:940)
    at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230)
    at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511)
    at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:242)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:167)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:335)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:304)
    ... 8 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException
    at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:920)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1181)
    at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
    ... 18 more
Caused by: java.lang.NullPointerException
    at com.sun.messaging.jms.ra.DirectConnectionFactory._createConnectionId(DirectConnectionFactory.java:424)
    at com.sun.messaging.jms.ra.DirectConnectionFactory._createConnection(DirectConnectionFactory.java:522)
    at com.sun.messaging.jms.ra.ManagedConnection.<init>(ManagedConnection.java:193)
    at com.sun.messaging.jms.ra.ManagedConnectionFactory.createManagedConnection(ManagedConnectionFactory.java:226)
    at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:147)
    at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:903)
    ... 20 more

我确信我正在关闭所有资源,但即使我没有关闭,我如何才能在第一次调用时用完连接池?

下面是ReadOfflineMessage.java代码中的代码。

try {
    QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup("jms/MyConnectionFactor");

    queueConnection = queueConnectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue = (Queue) context.lookup("jms/CloxQueue");
    QueueReceiver queueReceiver = queueSession.createReceiver(queue, "client_name = '" + clientName + "'");

    queueReceiver.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            if (message instanceof TextMessage) {
                try {
                    String clientMessage = ((TextMessage) message).getText();

                    System.out.println("Message: " + clientMessage);
                    clientMessage = clientMessage.replace("message:", "");
                    com.trinisoft.cloxserver.models.Message parsedMessage = parseMessage(clientMessage);
                    System.out.println("parsed Message: " + message);
                    Client toClient = ClientList.getClient(parsedMessage.getTo());
                    toClient.getClientWriter().append("message:" + clientMessage + "\n");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    queueConnection.start();
} catch (Exception e) {
    e.printStackTrace();
}

来自堆栈跟踪第 67 行是

queueConnection = queueConnectionFactory.createQueueConnection();

“谢谢”。

I have a JMS Application (using glass fish) that works perfectly on localhost. After deploying to my server, I keep getting the below stack trace on the FIRST CALL to the service.

#|2011-10-14T22:22:51.927+0400|WARNING|glassfish3.1|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors|_ThreadID=9342;_ThreadName=Thread-1;|RAR5117 : Failed to obtain/create connection from connection pool [ jms/MyConnectionFactor ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException|#]

[#|2011-10-14T22:22:51.928+0400|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=9342;_ThreadName=Thread-1;|com.sun.messaging.jms.JMSException: MQRA:DCF:allocation failure:createConnection:Error in allocating a connection. Cause: null
    at com.sun.messaging.jms.ra.DirectConnectionFactory._allocateConnection(DirectConnectionFactory.java:548)
    at com.sun.messaging.jms.ra.DirectConnectionFactory.createQueueConnection(DirectConnectionFactory.java:322)
    at com.sun.messaging.jms.ra.DirectConnectionFactory.createQueueConnection(DirectConnectionFactory.java:299)
    at com.clox.web.boot.ReadOfflineMessage.run(ReadOfflineMessage.java:67)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: null
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:310)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
    at com.sun.messaging.jms.ra.DirectConnectionFactory._allocateConnection(DirectConnectionFactory.java:543)
    ... 4 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException
    at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:103)
    at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1497)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:940)
    at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230)
    at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511)
    at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:242)
    at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:167)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:335)
    at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:304)
    ... 8 more
Caused by: com.sun.appserv.connectors.internal.api.PoolingException
    at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:920)
    at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1181)
    at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
    ... 18 more
Caused by: java.lang.NullPointerException
    at com.sun.messaging.jms.ra.DirectConnectionFactory._createConnectionId(DirectConnectionFactory.java:424)
    at com.sun.messaging.jms.ra.DirectConnectionFactory._createConnection(DirectConnectionFactory.java:522)
    at com.sun.messaging.jms.ra.ManagedConnection.<init>(ManagedConnection.java:193)
    at com.sun.messaging.jms.ra.ManagedConnectionFactory.createManagedConnection(ManagedConnectionFactory.java:226)
    at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:147)
    at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:903)
    ... 20 more

I am sure I am closing all resources, but even if I am not, how can I run out of connection pools right on the first call?

Below is the code in ReadOfflineMessage.java code.

try {
    QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup("jms/MyConnectionFactor");

    queueConnection = queueConnectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue = (Queue) context.lookup("jms/CloxQueue");
    QueueReceiver queueReceiver = queueSession.createReceiver(queue, "client_name = '" + clientName + "'");

    queueReceiver.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            if (message instanceof TextMessage) {
                try {
                    String clientMessage = ((TextMessage) message).getText();

                    System.out.println("Message: " + clientMessage);
                    clientMessage = clientMessage.replace("message:", "");
                    com.trinisoft.cloxserver.models.Message parsedMessage = parseMessage(clientMessage);
                    System.out.println("parsed Message: " + message);
                    Client toClient = ClientList.getClient(parsedMessage.getTo());
                    toClient.getClientWriter().append("message:" + clientMessage + "\n");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    queueConnection.start();
} catch (Exception e) {
    e.printStackTrace();
}

From the stack trace line 67 is

queueConnection = queueConnectionFactory.createQueueConnection();

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

━╋う一瞬間旳綻放 2024-12-17 05:29:50

好的,我发现问题了。这是一个内存问题。我的服务器上有 756MB。当我部署 JMS 应用程序时,还剩下 112MB。由于某种原因,glassfish 无法将剩余的 112MB 内存分配给 jms 池。我将我的 vps 升级到 1GB,一切都很好。

OK, I found the problem. It was a memory issue. I have 756MB on my server. When I deployed my JMS app, I have 112MB left. For some reason, glassfish couldn't allocate memory to jms pool from the 112MB left. I upgraded my vps to 1GB and all is well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文