多线程

来源:互联网 发布:php和ui哪个前景好 编辑:程序博客网 时间:2024/06/17 07:51
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!");
}
0 0
原创粉丝点击