Java 关于ThreadGroup#activeCount()的混淆

Java 关于ThreadGroup#activeCount()的混淆,java,multithreading,threadgroup,Java,Multithreading,Threadgroup,线程组#activeCount()的文档说明:返回此线程组及其子组中活动线程数量的估计值。 该计数是否包括处于睡眠、等待和加入模式的线程,还是仅包括正在执行运行方法的线程 谢谢。您可以轻松尝试以下方法: Thread t1 = new Thread(new Runnable() { @Override public void run() { Scanner sc = new Scanner(System.in); sc.nextInt();

线程组#activeCount()的文档说明:返回此线程组及其子组中活动线程数量的估计值。
该计数是否包括处于睡眠、等待和加入模式的线程,还是仅包括正在执行运行方法的线程


谢谢。

您可以轻松尝试以下方法:

Thread t1 = new Thread(new Runnable() {

    @Override
    public void run() {
        Scanner sc = new Scanner(System.in);
        sc.nextInt();
    }
});
Thread t2 = new Thread(new Runnable() {

    @Override
    public void run() {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
});
t1.start();   // this will be RUNNABLE
t2.start();   // this will be TIMED_WAITING
System.out.println(Thread.currentThread().getThreadGroup().activeCount());
打印3。评论台词

t1.start();
t2.start();
导致打印1