title: java hang at the end of program
body: <p>I have a java program which prints out the last statement of main program and hang. I would like to know what could cause this problem thanks.</p>
  
  <pre><code> public static void main(String[] args) {
  
          ...
          ...
          JSch jsch=new JSch();
      try {
  
          jsch.addIdentity("xxx");
          session = jsch.getSession("centos", this.ip, 22);
          session.setConfig("StrictHostKeyChecking", "no");
          session.connect();
  
      } catch (JSchException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      ...
      ...
          System.out.println("end of test");
      }
  </code></pre>
  
  <p>the program prints "end of test" and hang. what could cause this problem? I didnt use any framework.
  I compiled and run this in linux machine. after printing the "end of test", the linux prompt ">" doesnt show up</p>
  
  <p>from ps command, I see the process is running.</p>
  
  <p>i found the problem. the session conection doesnt get disconected. but why it blocks the exit? 
  correct me if i am wrong. there is no join or wait inside main thread. can main thread get blocked?</p>
  
  <p>Answer:
  with Stephen C 's help, 
  finally, i found the reason. in c++, all threads are terminated after main thread exit, but in java, JVM wait for all non-Daemon thread to complete. I applied my c++ knowledge to Java but they are different in this case. </p>