壓峇佩。。。
pool-1-thread-1屎壓峇佩。。。
pool-1-thread-1屎壓峇佩。。。
Process finished with exit code 0
鎗、徭協吶?殻学
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Java?殻??殻学-徭協吶?殻学
*
* @author Administrator
*/
public class Test {
public static void main(String[] args) {
//幹秀吉棋錦双
BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue<Runnable>(20);
//幹秀匯倖汽?殻峇佩殻會?万辛芦電壓公協决岳朔塰佩凋綜賜宀協豚仇峇佩。
ThreadPoolExecutor pool = new ThreadPoolExecutor(2,3,2,TimeUnit.MILLISECONDS,bqueue);
//幹秀糞?阻Runnable俊笥斤??Thread斤?輝隼匆糞?阻Runnable俊笥
Thread t1 = new MyThread();
Thread t2 = new MyThread();
Thread t3 = new MyThread();
Thread t4 = new MyThread();
Thread t5 = new MyThread();
Thread t6 = new MyThread();
Thread t7 = new MyThread();
//繍?殻慧秘学嶄序佩峇佩
pool.execute(t1);
pool.execute(t2);
pool.execute(t3);
pool.execute(t4);
pool.execute(t5);
pool.execute(t6);
pool.execute(t7);
//購液?殻学
pool.shutdown();
}
}
class MyThread extends Thread {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "屎壓峇佩。。。");
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
pool-1-thread-1屎壓峇佩。。。
pool-1-thread-2屎壓峇佩。。。
pool-1-thread-2屎壓峇佩。。。
pool-1-thread-1屎壓峇佩。。。
pool-1-thread-2屎壓峇佩。。。
pool-1-thread-1屎壓峇佩。。。
pool-1-thread-2屎壓峇佩。。。
Process finished with exit code 0
Java线程:新特征-线程池(4)
时间:2011-02-20 51cto博客 leizhimin
创建自定义线程池的构造方法很多,本例中参数的含义如下:
ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
|