【发布时间】:2010-01-16 18:36:49
【问题描述】:
我刚刚在 http://java.sun.com/docs/books/tutorial/rmi/implementing.htmlhttp://java.sun.com/docs/books/tutorial/rmi/implementing.html 上阅读了关于 RMI 的 Trail。
当我运行该示例时,尽管 main 已完成,但 JVM 并未终止。 RMI 是否在内部某处产生线程?
main 退出后,main 中产生的多个线程的行为是什么? 让线程随时退出是一种干净的方法,还是应该在生成的每个线程上进行连接?我没有找到关于这个问题的任何文档。
非常感谢您的帮助!!
public class ComputeEngine implements Compute {
public ComputeEngine() {
super();
}
public <T> T executeTask(Task<T> t) {
return t.execute();
}
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Compute engine = new ComputeEngine();
Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);
System.out.println("ComputeEngine bound");
} catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}
【问题讨论】:
-
非常感谢您的有用回答!
标签: java multithreading rmi