/**
* @Author ex-liujiwei
* @Date 2022/1/6 14:28
*/
@Service
public class ConcurrentService {
public static void test01(){
// 创建线程池
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("liujiwei-pool-%d").build();
ExecutorService executorService = new ThreadPoolExecutor(10, 10, 0L,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), threadFactory, new ThreadPoolExecutor.AbortPolicy());
Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
};
try{
executorService.submit(runnable);
}catch (Exception e){
System.out.println(e);
}finally {
executorService.shutdown();
}
}
public static void test02(){
System.out.println(Thread.currentThread().getName());
}
public static void test03(){
System.out.println(Thread.currentThread().getName());
}
public static void main(String[] args) {
test01();
test02();
test03();
}
}
单独用一个线程执行任务
最新推荐文章于 2023-06-03 23:26:09 发布