1

I am using eclipse juno and in debug window I am seeing so many threads running and there is entry as

Thread [pool-485-thread-1] Running

what does this entry explains.
Is it there are 485 threads in a single pool or 485 different pools?
This entry is regularly increasing i.e. it is now Thread [pool-1125-thread-1] Running. Is this a problem?

4

3 回答 3

4

这很可能来自 DefaultThreadFactory 类(如下所示)。这表明自 JVM 启动以来您已经创建了 485 个池,并且这个线程是第 485 个池中的第一个线程。

如果这些池在很长一段时间内被创建和销毁,这并不一定表示存在严重问题。然而,像这样继续创建线程池有点奇怪——也许值得看看你的代码,看看你是否可以重用一些线程池(这可能有助于提高应用程序的性能)。

static class DefaultThreadFactory implements ThreadFactory {
    private static final AtomicInteger poolNumber = new AtomicInteger(1);
    private final ThreadGroup group;
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;

    DefaultThreadFactory() {
        SecurityManager s = System.getSecurityManager();
        group = (s != null) ? s.getThreadGroup() :
                              Thread.currentThread().getThreadGroup();
        namePrefix = "pool-" +
                      poolNumber.getAndIncrement() +
                     "-thread-";
    }

    public Thread newThread(Runnable r) {
        Thread t = new Thread(group, r,
                              namePrefix + threadNumber.getAndIncrement(),
                              0);
        if (t.isDaemon())
            t.setDaemon(false);
        if (t.getPriority() != Thread.NORM_PRIORITY)
            t.setPriority(Thread.NORM_PRIORITY);
        return t;
    }
}
于 2013-10-15T13:27:45.037 回答
1

That looks like the default name of the thread assigned by the thread factory. I can only assume you're creating new thread pools instead of new threads.

于 2013-10-15T13:30:43.643 回答
1

标题 Thread[pool-485-thread-1] 是什么意思...

它意味着创建该 Thread 的特定线程池的任何含义。假设您知道线程在做什么,您应该能够弄清楚是什么创建了它们……然后确认“明显”的含义是正确的。

这是一个问题吗?

从表面上看,应用程序似乎在重复创建线程池......这很可能意味着线程池在回收线程方面无效。这对性能不利。

于 2013-10-15T13:26:14.210 回答