您好,登錄后才能下訂單哦!
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Test { public static void main(String[] args) { //設置線程數 ExecutorService service = Executors.newFixedThreadPool(5); for(int i= 0;i<10;i++){ service.execute(new RunnableImpl(i)); } service.shutdown(); } private static class RunnableImpl implements Runnable { private int id; private RunnableImpl(int id) { this.id = id; } public void run() { System.out.println("開始執行" + id); try { Thread.sleep(2000); } catch (InterruptedException e) { // nothing to do } System.out.println(id + "執行完畢。"); } @Override public String toString() { return "線程" + id; } } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。