public class test {
    public static void main(String[] args) {
        frame tmp;
        tmp=new frame();
        ExecutorService executor;
        executor=Executors.newCachedThreadPool();
        executor.execute(tmp);
        executor.shutdown();
    }
}
  public class frame extends JFrame implements Runnable{
        int lis;
       public frame()
      {
        setVisible(true);
        lis=1;
        addWindowListener(
          new WindowAdapter() 
          {              
              public void windowClosing(WindowEvent event)
              {
                  lis=0;                 
              }
          }
        );
       }
       @Override
       public void run() {
        while(lis==1)
        {
        }
        JOptionPane.showMessageDialog(null,"close");
      }    
}
the sequence of steps which i thought will happen after running class test
1) jframe gets displayed and runs in a seperate thread
2) after closing the jframe,the thread completes its execution and executor shut's down
3)class test terminate's since all the statements are executed.
but when i run the class test
after closing the jframe class test is not terminating
any explanation or reference would be helpful. thank you
EDIT:suppose i created two frames.i want the program to exit only after all the frames are closed not just one jframe.