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);
}
}
}
}
这是主类代码,不知道哪有问题了,帮忙看看吧

解决方案 »

  1.   

    是主线程死还是新开的线程死?
    RSThread是你自己定义的类吗?在run方法里写catch语句,并把异常记录下来看看。
      

  2.   

    RSThread是我自定义的类,处理事件的类,是整个程序就不运行了,进程死掉了,都catch异常了,但是什么也没捕捉到
    我是放在linux下的,用ps -ef |grep java ,查看该程序进程是否存在,刚开始还在的,但过个一两个小时就没了,很奇怪啊。。也没有异常打出来
      

  3.   

    会不会是发生了error,
    把catch(Exception e) 改为catch(Throwable e)试下。 
      

  4.   

    你应该在无限循环内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