用了线程池,开启了几十个线程。不知咋回事儿,运行几个或几十个个小时后,日志中见不到他们的踪影了。
想监视他们的状态,是卡的,还是死了,怎么死的,死在哪?
怎么线程堆栈如何查看?
谢谢哦

解决方案 »

  1.   

    线程池的地方在新增或者删除线程的时候加一个debug信息。如果在命令行下面启动的话用ctrl + break就可以看到当前哪些线程在运行了
      

  2.   


    感谢您的热心解答。请问怎么增加debug信息。
    还是怎样
      

  3.   

    线程池的地方在新增或者删除线程的时候加一个debug信息。
    如果在命令行下面启动的话用ctrl + break就可以看到当前哪些线程在运行了
      

  4.   

    呵呵,增加debug信息想怎么增就怎么增撒,System.out.println("添加线程了")或者logger.info("添加线程了")都可以嘛,看你自己。。找到线程池新增线程的地方把这个加进去就是了。。
      

  5.   

    运行Callable任务可拿到一个Future对象,
    通过Future对象可了解任务执行情况,可取消任务的执行,还可获取任务执行的结果。
      

  6.   

    callable接口(就比runnable接口的方法多了返回值)public interface Callable<v>{
     v call() throw Exception;
    }Future接口(封装了线程的计算结果)public interface Future<v>{
     
      v get();
      v get(long timeout,TimeUnit unit);
      void cancel(boolean mayInterruot);
      boolean isDone();
    }FutureTask包装器可以把callable转换成Future和Runnable的机制 他实现了这两个接口Callable<Integer> myResult=;
    FutureTask<Integer> task=new FutureTask<Integer>(myResult);
    Thread t = new Thread(task);//实现了Runnable接口
    t.start();
    ...
    Integer result = task.get();//实现了Future接口
      

  7.   

            Thread bt = null;
            str.append("Trace info:\r\n");
            for (int i = 0; i < runThreads.size(); i++) {
                bt = runThreads.get(i);
                str.append(bt);
                str.append(" state:");
                str.append(bt.getState().toString());
                str.append("\r\n");
                try{
                    StackTraceElement[] ste = bt.getStackTrace();
                    for (int j = 0; j < ste.length; j++) {
                        str.append(ste[j]);
                        str.append("\r\n");
                    }
                }
                catch(Exception e){
                    str.append("trace fail ...");
                }
            }