线程池提问?开了几个线程池?然后开了几个线程?

dada0827 2015-08-19 04:55:17
package com.sunfun.util;

import java.util.ArrayList;

import org.apache.log4j.Logger;

public class PoolManager {

private Logger logger = Logger.getLogger(PoolManager.class);

public static PoolManager mPool = new PoolManager();
public final int max_pool = 1;
public final int max_Tasks = 10;
public static ArrayList<Worker> init_pools;
private TaskMonitorThread mainThread;

static {
init_pools = new ArrayList<Worker>(10);
}

public static PoolManager getInstance() {
if (mPool == null) {
mPool = new PoolManager();
}

return mPool;
}

// 获取空闲线程
public Worker getIdleThread() {
Worker working = null;
while (true) {
synchronized (init_pools) {
for (int i = 0; i < max_pool; i++) {
working = init_pools.get(i);
if (!working.isrunning) {
return working;
}
}
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public void init() {
logger.info("线程池初始化开始。。。");
Worker worker = null;
for (int i = 0; i < this.max_pool; i++) {
worker = new Worker("initThread" + i);
init_pools.add(worker);
worker.start();
}
mainThread = new TaskMonitorThread();
mainThread.start();
logger.info("结束初始化线程池...");
}

public void destory() {
logger.info("线程池销毁。。。");
init_pools.clear();
}

}
...全文
106 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qqw6789567 2015-08-19
这种问题没人回答的!!!!!!!
回复
dada0827 2015-08-19
线程池提问?开了几个线程池?然后开了几个线程? public final int max_pool = 1;是表示开了一个线程池还是最大线程是一个?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-08-19 04:55
社区公告
暂无公告