Пример #1
1
 public String getGeneralStats() {
   TextBuilder tb = new TextBuilder();
   ThreadFactory tf = _generalThreadPool.getThreadFactory();
   if (tf instanceof PriorityThreadFactory) {
     tb.append("General Thread Pool:\r\n");
     tb.append("Tasks in the queue: " + _generalThreadPool.getQueue().size() + "\r\n");
     tb.append("Showing threads stack trace:\r\n");
     PriorityThreadFactory ptf = (PriorityThreadFactory) tf;
     int count = ptf.getGroup().activeCount();
     Thread[] threads = new Thread[count + 2];
     ptf.getGroup().enumerate(threads);
     tb.append("There should be " + count + " Threads\r\n");
     for (Thread t : threads) {
       if (t == null) {
         continue;
       }
       tb.append(t.getName() + "\r\n");
       for (StackTraceElement ste : t.getStackTrace()) {
         tb.append(ste.toString());
         tb.append("\r\n");
       }
     }
   }
   tb.append("Packet Tp stack traces printed.\r\n");
   return tb.toString();
 }
Пример #2
1
  public String getGeneralStats() {
    final StringBuilder sb = new StringBuilder(1000);
    ThreadFactory tf = _generalThreadPool.getThreadFactory();

    if (tf instanceof PriorityThreadFactory) {
      PriorityThreadFactory ptf = (PriorityThreadFactory) tf;
      int count = ptf.getGroup().activeCount();
      Thread[] threads = new Thread[count + 2];
      ptf.getGroup().enumerate(threads);
      StringUtil.append(
          sb,
          "General Thread Pool:\r\n" + "Tasks in the queue: ",
          String.valueOf(_generalThreadPool.getQueue().size()),
          "\r\n" + "Showing threads stack trace:\r\n" + "There should be ",
          String.valueOf(count),
          " Threads\r\n");

      for (Thread t : threads) {
        if (t == null) continue;

        StringUtil.append(sb, t.getName(), "\r\n");

        for (StackTraceElement ste : t.getStackTrace()) {
          StringUtil.append(sb, ste.toString(), "\r\n");
        }
      }
    }

    sb.append("Packet Tp stack traces printed.\r\n");

    return sb.toString();
  }
Пример #3
0
 @GwtIncompatible // TODO
 private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
   executor.setThreadFactory(
       new ThreadFactoryBuilder()
           .setDaemon(true)
           .setThreadFactory(executor.getThreadFactory())
           .build());
 }
Пример #4
0
 /**
  * Create a new {@link ThreadPoolRejectedExecutionException}.
  *
  * @param r the task that was rejected.
  * @param reason the reason this task was rejected.
  */
 public ThreadPoolRejectedExecutionException(
     Runnable r, ThreadPoolExecutor pool, String reason) {
   super(
       "REJECTED EXECUTION[runnable= "
           + r
           + ", factory= "
           + pool.getThreadFactory()
           + ", reason= "
           + reason
           + "]");
 }
 private void configure(final String name) {
   /*
    * All executors should be shutdown on application shutdown.
    */
   ShutdownHookManager.register(shutdownHook);
   /*
    * All threads should stop after 60 seconds of idle time
    */
   delegate.setKeepAliveTime(
       FIXED_THREAD_KEEPALIVE_TIMEOUT.longValue(), FIXED_THREAD_KEEPALIVE_TIMEOUT.getTimeUnit());
   /*
    * Fixes non starting with corepoolsize von 0 and not filled queue (Java Conurrency In Practice Chapter 8.3.1).
    * If this bug can occur, a exception would be thrown here.
    */
   delegate.allowCoreThreadTimeOut(true);
   /*
    * Named threads improve debugging.
    */
   delegate.setThreadFactory(new WrappedThreadFactory(name, delegate.getThreadFactory()));
 }