本帖最后由 田向向 于 2012-7-6 16:48 编辑
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CloseResource {
public static void main(String[] args) throws Exception {
ExecutorService exec = Executors.newCachedThreadPool();
exec.execute(new IOBlockedTest(System.in));
exec.shutdownNow();
System.in.close();
System.out.println("done");
}
}
class IOBlockedTest implements Runnable {
private InputStream in;
public IOBlockedTest(InputStream is) {
in = is;
}
public void run() {
try {
System.out.println("Waiting for read():");
in.read();
} catch (Exception e) {
if (Thread.currentThread().isInterrupted()) {
System.out.println("Interrupted from blocked I/O");
} else {
throw new RuntimeException(e);
}
}
System.out.println("Exiting IOblocked.run()");
}
}
为什么运行结果会只输出了Waiting for read():,哪位高手能给我解释一下这个程序?
|
|