import java.util.concurrent.CountDownLatch;
/**
* 多线程测试模板
*
* @author Mairuis
* @date 2018/10/11
*/
public class ConcurrentTest {
public static class Context{
public Context(){
}
}
public static CountDownLatch countDownLatch = new CountDownLatch(3);
public static Context context = new Context();
public static void main(String[] args) throws Exception {
Thread t1 = new Thread(ConcurrentTest::firstThread);
Thread t2 = new Thread(ConcurrentTest::secondThread);
t1.start();
t2.start();
countDownLatch.countDown();
singleThread();
}
public static void firstThread(){
try {
countDownLatch.countDown();
countDownLatch.await();
firstThread0(context);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void secondThread(){
try {
countDownLatch.countDown();
countDownLatch.await();
secondThread0(context);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 最后一个执行的线程
* @throws Exception
*/
public static void singleThread() throws Exception{
}
/**
* 第一个线程 与第二个同时执行
* @param context
* @throws Exception
*/
public static void firstThread0(Context context) throws Exception{
}
/**
* 第二个线程
* @param context
* @throws Exception
*/
public static void secondThread0(Context context) throws Exception{
}
}
【学习笔记】Java-Concurrent-多线程测试模板
猜你喜欢
转载自blog.csdn.net/qq_34622036/article/details/83750415
今日推荐
周排行