多線程

public static void main(String[] args) throws Exception {
     
    Thread threadOne = new Thread(new Runnable() {
        public void run() {
            methodOne();
        }
    });
     
    Thread threadTwo = new Thread(new Runnable() {
        public void run() {
            methodTwo();
        }
    });
     
    // 執行線程
    threadOne.start();
    threadTwo.start();
     
    Thread.sleep(1000);
}
 
public static void methodOne() {
    System.out.println("Method one is running!");
}
 
public static void methodTwo() {
    System.out.println("Method two is running!");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章