第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ThreadGroup.activeCount() 方法在 java 中不起作用

ThreadGroup.activeCount() 方法在 java 中不起作用

GCT1015 2024-01-28 16:22:19
我正在學(xué)習(xí)多線程的概念,我試圖查找數(shù)組中的活動線程數(shù),但ThreadGroup.activeCount()方法僅返回零值。這是代碼:線程對象類:-class th1 extends Thread{    public th1(String threadName, ThreadGroup tg1)    {        super(tg1, threadName);    }    @Override    public void run()     {        try {            Thread.sleep(5000);        }         catch (InterruptedException e)         {            e.printStackTrace();        }        System.out.println(Thread.currentThread().getName() + " is running");    }}主要課程:-public class enumerate_demo {    public static void main(String[] args)     {        ThreadGroup tg1 = new ThreadGroup("group 1");        Thread t1 = new Thread(new th1("t-1", tg1));        t1.start();        Thread t2 = new Thread(new th1("t-2", tg1));        t2.start();        Thread t3 = new Thread(new th1("t-3", tg1));        t3.start();        System.out.println("Number of active count :- " + tg1.activeCount());        Thread[] group = new Thread[tg1.activeCount()];        int count = tg1.enumerate(group);        for (int i = 0; i < count; i++)        {            System.out.println("Thread " + group[i].getName());        }    }}
查看完整描述

1 回答

?
慕斯王

TA貢獻1864條經(jīng)驗 獲得超2個贊

問題是,在創(chuàng)建實例th1類時,您將它們用作RunnableThread. 這些包裝線程不與任何ThreadGroup. 聲明變量如下。

        Thread t1 = new th1("t-1", tg1);
        t1.start();


查看完整回答
反對 回復(fù) 2024-01-28
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號