我需要创建一堆到不同主机的 JMX 连接。我正在尝试并行创建这些连接。现在在这方面的表现要好得多。
我已经将“主机和端口”条目的集合传递给该方法。对于每个条目,将创建一个连接。
现在我正在提交创建与多个线程的连接的任务。但我不知道如何返回并存储线程创建的连接对象。
代码是这样的,
ConnectionFactory.createConnections(collection of hostportEntries)
class ConnectionFactory{
public static CollectionOfConnections createConnections(ListOfHostPorts)
{
ExecutorService exec = Executors.newFixedThreadPool(4);
for(iterate over hostportEntries)
{
Future<Connection> future1 = exec.submit(new connCreator(HostPortEntry));
//Now here, connCreator is implementing Callable Interface and creating connection. and returning it. I'm taking reference of that Returned connection.
//But how will I take Multiple Connection objects returned by Multiple threads. I tried to create Future[] but OPTION like that doesn't seem to be there
// Can anybody help here?????
}
//if I succeed in getting the objects return then I'll store in one more collection and return those for further use of those connections.
}