67,515
社区成员
发帖
与我相关
我的任务
分享
package com.meran.normalTest;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class CSDNDemo {
public synchronized void step() throws InterruptedException{
TimeUnit.SECONDS.sleep(4);
System.out.println(Thread.currentThread()+"执行step 1");
TimeUnit.SECONDS.sleep(4);
}
public synchronized void step2(){
System.out.println(Thread.currentThread()+"执行step2");
}
public static void main(String [] args) throws InterruptedException{
CSDNDemo temp=new CSDNDemo();
Thread t1=new Thread(temp.new A());
t1.start();
TimeUnit.SECONDS.sleep(1);
Thread t2=new Thread(temp.new B());
t2.start();
}
class A implements Runnable{
public void run(){
try {
step();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class B implements Runnable{
@Override
public void run() {
step2();
}
}
}