RabbitMQ java客户端内存泄漏

时间:2014-02-20 14:59:09

标签: java memory-leaks rabbitmq

我正在使用amqp-client-3.2.2.jar和jdk 32位。

我有一个在应用程序中运行的java消息生成器,以及在不同应用程序中运行的java消息使用者。两者都在我的笔记本电脑上运行,每个都来自自己的可执行jar文件。

我正在查看任务管理器对这两个应用程序的内存分配。

两种应用程序的内存分配都在迅速增加。

我已经简化了消费者代码(如下所示),只是为了调查并希望解决这个漏洞:

Connection _connection = null;
Channel _channel = null;
QueueingConsumer _consumer = null;
boolean _stop = false;

try {
    ConnectionFactory _factory = new ConnectionFactory();
    _factory.setHost("localhost");
    _factory.setRequestedHeartbeat(5);
    _connection = _factory.newConnection();
    _channel = _connection.createChannel();
    _channel.exchangeDeclare("keyboard_exchange", "fanout", false, true, null);
    _channel.exchangeDeclare("java_keyboard_exchange", "topic", false, true, null);
    _channel.exchangeBind("java_keyboard_exchange", "keyboard_exchange", "#");
    _channel.queueDeclare("java_keyboard_queue", false, false, false, null);
    _channel.queueBind("java_keyboard_queue", "java_keyboard_exchange", "#");
    _consumer = new QueueingConsumer(_channel);
    _channel.basicConsume("java_keyboard_queue", false, _consumer);
} catch (Exception ex) {
    System.out.println("Exception occurred while creating objects: " + ex);
    _stop = true;
}

QueueingConsumer.Delivery delivery = null;

while (_stop == false) {
    try {
        delivery = _consumer.nextDelivery();
        byte[] msg = delivery.getBody();
        System.out.println(" Received: bytes=" + msg.length + " msg=" + msg);
        _consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);
    } catch (Exception e) {
        e.printStackTrace();
        _stop = true;
    }
}

0 个答案:

没有答案