title: Why does JVM does not terminate when using RMI
body: <p>I just read the Trail on RMI from sun at <a href="http://java.sun.com/docs/books/tutorial/rmi/implementing.html" rel="nofollow noreferrer">http://java.sun.com/docs/books/tutorial/rmi/implementing.html</a></p>
  
  <p>When I run the example, the JVM does not terminate although main has finished. Is RMI spawning a Thread somewhere internally? </p>
  
  <p>What is the behaviour of multiple Threads spawned in main, after main exits?
  Is it a clean way to let the Threads exit whenever they want or should you do a join on each Thread you spawn? I did not find any documentation on this question.</p>
  
  <p>Thank you very much for your help!!</p>
  
  <pre><code>public class ComputeEngine implements Compute {
  
      public ComputeEngine() {
          super();
      }
  
      public &lt;T&gt; T executeTask(Task&lt;T&gt; 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();
          }
      }
  }
  </code></pre>