Thread使用

1.方法一:业务逻辑Runnable与线程控制Thread分离

public class Test implements Runnable{
      @Override
       public void run(){
        }
}

public class MyProject{
       Test test = new Test();  
       Thread t = new Thread(test,"t-name");
        t.start();
}

2. 方法二

public class Do{
      public void Play(){
      }

      public void Sing(){
      }
}

public class MyProject{

      public static void main(String[] args){
        new Thread(Do::Play).start();

//or
         new Thread(()->{

           //Todo
         }).start();
} }

猜你喜欢

转载自www.cnblogs.com/anenyang/p/12642524.html
今日推荐