我想使用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 Thread一起使用?