从多个Java线程发送消息

从多个Java线程发送消息,java,rabbitmq,Java,Rabbitmq,我想使用ExecutorService,以便使用多个Java线程来发送和接收带有RabbitMQ的消息: public class EndPoint { public ExecutorService es; public EndPoint(String endpointName) throws Exception { es = Executors.newFixedThreadPool(20); Connectio

我想使用ExecutorService,以便使用多个Java线程来发送和接收带有RabbitMQ的消息:

public class EndPoint {

    public ExecutorService es;  
    public EndPoint(String endpointName) throws Exception {     
        es = Executors.newFixedThreadPool(20);          
        ConnectionFactory factory = new ConnectionFactory();            
        connection = factory.newConnection(es);
        channel = connection.createChannel();
        ..........
    }

    private static EndPoint single_instance = null; 
    public static EndPoint getInstance() throws Exception
    {
        if (single_instance == null)
            single_instance = new EndPoint(null);

        return single_instance;
    }
}
在某些远程类中:

EndPoint vvvv = EndPoint.getInstance();
vvvv.es.execute(some content);
如何从多个线程发送和接收数据?到目前为止,我创建的代码

channel.basicPublish(EXCHANGE_NAME, endPointName, null, SerializationUtils.serialize(object));

但是上面的代码如何与Java线程一起使用呢?

只是一些小建议:1)使
es
final也称为“readonly”,2)使构造函数
private
,3)删除构造函数参数
endpointName
(看起来它总是空的,因为您只创建了一个实例)@Lino谢谢。你能给我一些关于这个问题的代码示例吗?你应该阅读他们的API。他们说不要在多个线程之间共享通道,但是您可以在这个通道上调用某些操作。除了“basicPublish”之外,您没有给出任何要在此处调用的操作。您需要找到它们允许的更多操作。您知道如何在RabbitMQ中使用多线程吗?每个线程可能有不同的通道?