java 多线程, 程序执行时,想使用 Future 特性捕获异常,做进一步的处理。运行程序时发生了异常,但并没有捕获到异常。
相关代码结构如下:
ExecutorService executor = Executors.newFixedThreadPool(3); Future<Object> future = null; for (int i = 0; i < 3; i++) { future = executor.submit(new ThreadDemo()); try { future.get(); } catch (InterruptedException e) { System.out.println(String.format("handle exception in child thread. %s", e)); } catch (ExecutionException e) { System.out.println(String.format("handle exception in child thread. %s", e)); } } ///// call 方法实现 @Override public String call() throws Exception { try { client.runMethod(ip); } catch (Exception e) { System.out.println(String.format("handle exception in child thread. %s", e)); } return ""; } 在服务器端执行程序时报错,但并未捕获到异常。
java.rmi.ConnectException: Connection refused to host: 172.17.0.6; nested exception is: java.net.ConnectException: Connection refused (Connection refused) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338) at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:112) at java.rmi.Naming.lookup(Naming.java:101) at com.net.client.DataNodeRemoteClient.runRemoteMethod(DataNodeRemoteClient.java:27) at com.net.client.DataNodeRemoteClientCallableThread$runTheThread.call(DataNodeRemoteClientCallableThread.java:84) at com.net.client.DataNodeRemoteClientCallableThread$runTheThread.call(DataNodeRemoteClientCallableThread.java:1) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.net.ConnectException: Connection refused (Connection refused) 是少了哪些步骤或者哪里操作有问题?
