- ExecutorService executorService = Executors.newFixedThreadPool(2);
- for(intj=0;j<10;j++){
- final intt = j;
- executorService.execute( new Runnable(){
- @Override
- public void run() {
- for(inti=0;i<4;i++){
- String s = "t:" + t + "," + "i:" + i + ", tid:" + Thread.currentThread().getId();
- System.out.println(s);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- });
- }
- executorService.shutdownNow();
来源: http://www.bubuko.com/infodetail-1995069.html