手记

创建缓冲池进行执行线程操作

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

package demo04;

 

import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

 

public class Test01   {

    public static void main(String[]   args) {

    ExecutorService   ex=Executors.newCachedThreadPool();

    Runnable run1=new Runnable() {

@Override

public void run()   {

                 for(int i=0;i<100;i++){

                if(i%2==1){

                System.out.println(Thread.currentThread().getName()+":"+i);

                }

                 }

}

};

ex.execute(run1);

    ex.execute(new Runnable() {

@Override

public void run()   {

for(int i=0;i<100;i++){

if(i%2==0){

System.out.println(Thread.currentThread().getName()+":"+i);

}

}

}

});

}

}

原文链接:http://www.apkbus.com/blog-813041-60901.html

0人推荐
随时随地看视频
慕课网APP