The purpose of this lab is to create three threads and run them at the same time. While are running they will be printing out their name in the console. By observing what is printed in the console, you can observe how the threads run and in which order.
package java3.T13;
public class RunnableDemo {
public static void main(String[] args) {
MyThread myThread= new MyThread ();
//创建并启动线程
Thread ta = new Thread(myThread);
Thread tb = new Thread(myThread);
Thread tc = new Thread(myThread);
ta.start();
tb.start();
tc.start();
}
}
class MyThread implements Runnable{
public void PrintMe(){
for(int i=0;i<10;i++) {
try {
System.out.println(Thread.currentThread().getName()+i);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void run() {
PrintMe();
}
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632