没有废话,直接上代码 ---依赖包 import java.util.concurrent.ExecutorService;
---创建实例 ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); executorService.execute(new rb("rb1"));
---实现 public class rb implements Runnable { private String name; public VrpRunnable(String name) { this.name = name; } @Override public void run() { System.out.println("启动" + name + "......"); try { for (int i = 0; i < 5; i++) { Thread.sleep(1000); } } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(name+"执行完成"); } }