JAva interrupedの使い方

1347 ワード

1 interruped
java      sleep ,           ,              interrupt(),        interrupt  。
      ,        ,    ,        interrupt()   ,  s    。
             Thread.currentThread().interrupt();
public static void main(String[] args) throws InterruptedException
    {
        Thread s =  new Thread(){
            public void run(){
                while(!interrupted()){
                    System.out.println("------");
                    try{
                        sleep(5000);
                    } catch (InterruptedException e) {
                        //Thread.currentThread().interrupt();
                        System.out.println("  ");
                    }
                    System.out.println(".......");
                }
            }
        };
        s.start();
       
        Thread.currentThread().sleep(2000);
        s.interrupt();
    }
2.synchronized wait  
synchronized              ,      , wait                ,           notify,notifyAll ,jvm       
3.  synchronized
synchronized            ,  synchronized      class  
4.stop           ,      stop ,                ,                 ,       ,