使用PooledExecutor后,进程总是莫名其妙的死掉,高手看看。。。

chenwei023 2009-01-08 09:50:12
public static void main(String args[]) {
// 初始化日志配置文件
PropertyConfigurator.configure(com.ccit.util.StaticValue.log4jFilePath);
logger.info("***************************************************");
logger.info("* SockServerApp Service Start *");
logger.info("***************************************************");
// 初始化配置文件变量
Socket client = null;

try {

PooledExecutor pool = new PooledExecutor(new BoundedBuffer(
(ReadConfig.getInstance().getMaxpoolsize()).intValue()),
(ReadConfig.getInstance().getPoolqueue()).intValue());

// 设置线程池的最小线程数
pool.setMinimumPoolSize((ReadConfig.getInstance().getMinpoolsize())
.intValue());
// 设置线程池中线程的存活时间
pool.setKeepAliveTime((ReadConfig.getInstance().getCallTimeOut())
.intValue());
int port = (ReadConfig.getInstance().getPort()).intValue();

logger.debug("port =" + port);
// 建立监听socket
ServerSocket server = new ServerSocket(port);
while (true) {
client = server.accept();
logger.debug("client 接受到请求===== " + client);
logger.debug("client 进入程序进行处理===== " + client);
pool.execute(new RSThread(client));
}

} catch (Exception e) {
logger.error(e.toString(), e);
} finally {
if (client != null) {
try {
client.close();
} catch (Exception e) {
logger.error(e.toString(), e);
}
}
}
}
这是主类代码,不知道哪有问题了,帮忙看看吧
...全文
339 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
MT502 2009-01-08
  • 打赏
  • 举报
回复
你应该在无限循环内catch异常,这样即使有某个线程产生异常死掉,也不会导致退出循环使得进程终止:
public static void main(String[] args) {
// 初始化日志配置文件
PropertyConfigurator.configure(com.ccit.util.StaticValue.log4jFilePath);
logger.info("***************************************************");
logger.info("* SockServerApp Service Start *");
logger.info("***************************************************");
// 初始化配置文件变量
PooledExecutor pool = new PooledExecutor(new BoundedBuffer((ReadConfig
.getInstance().getMaxpoolsize()).intValue()), (ReadConfig
.getInstance().getPoolqueue()).intValue());

// 设置线程池的最小线程数
pool.setMinimumPoolSize((ReadConfig.getInstance().getMinpoolsize())
.intValue());
// 设置线程池中线程的存活时间
pool.setKeepAliveTime((ReadConfig.getInstance().getCallTimeOut())
.intValue());
int port = (ReadConfig.getInstance().getPort()).intValue();

logger.debug("port =" + port);
// 建立监听socket
ServerSocket server = new ServerSocket(port);
while (true) {
Socket client = null;
try {
client = server.accept();
logger.debug("client 接受到请求===== " + client);
logger.debug("client 进入程序进行处理===== " + client);
pool.execute(new RSThread(client));
} catch (Throwable e) {
logger.error(e.toString(), e);
} finally {
if (client != null) {
try {
client.close();
} catch (Exception e) {
logger.error(e.toString(), e);
}
}
}

}

}

顺便catch一下Throwable看看是什么error
chenchuanfeng001 2009-01-08
  • 打赏
  • 举报
回复
会不会是发生了error,
把catch(Exception e) 改为catch(Throwable e)试下。
chenwei023 2009-01-08
  • 打赏
  • 举报
回复
RSThread是我自定义的类,处理事件的类,是整个程序就不运行了,进程死掉了,都catch异常了,但是什么也没捕捉到
我是放在linux下的,用ps -ef |grep java ,查看该程序进程是否存在,刚开始还在的,但过个一两个小时就没了,很奇怪啊。。也没有异常打出来
Dream_JavaWorld 2009-01-08
  • 打赏
  • 举报
回复
mark
chenchuanfeng001 2009-01-08
  • 打赏
  • 举报
回复
是主线程死还是新开的线程死?
RSThread是你自己定义的类吗?在run方法里写catch语句,并把异常记录下来看看。
meihuiyu 2009-01-08
  • 打赏
  • 举报
回复
mark
tiandiqing 2009-01-08
  • 打赏
  • 举报
回复
关注
Dream_JavaWorld 2009-01-08
  • 打赏
  • 举报
回复
mark
chenwei023 2009-01-08
  • 打赏
  • 举报
回复
关键是什么异常都没有啊。。。。自动就死掉了。。是不是线程的问题啊??
fulianglove 2009-01-08
  • 打赏
  • 举报
回复
贴出异常的信息啊,不然大家怎么帮你看
chenwei023 2009-01-08
  • 打赏
  • 举报
回复
高手回答啊,在线等。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧