Thread

时间:2023-03-09 07:28:54
Thread

问题:编写一个能提现多线程的例子?假设有t1,t2两个线程,如何保证t2线程在t1线程执行完后再执行?

 package cn.changb.thread;

 public class MyThread implements Runnable {

     @Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 100; i++) {
System.out.println(Thread.currentThread().getName() + "-" + i);
}
} }
 package cn.changb.thread;

 public class ThreadTest {

     public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Thread thread = new Thread(new MyThread());
thread.start();
thread.join();// 在上述线程执行结束后再执行后续线程的内容
new Thread(new MyThread()).start();
} }