线程练习题

来源:互联网 发布:医院挂号哪个软件好 编辑:程序博客网 时间:2024/06/06 07:22

package app;

public class threadTest {

public static void main(String[] args) {    person pp = new  person();    for(int i = 0;i<10;i++){        new Thread(pp).start();    }}


class person implements Runnable {

@Overridepublic void run() {    thought();}public synchronized void thought(){    try {        System.out.println(Thread.currentThread().getName()+"通过山洞");        Thread.sleep(2000);    } catch (InterruptedException e) {        e.printStackTrace();    }}

}

原创粉丝点击