Ruang penulis
← Kembali ke jurnal
Core API

How do I get number of active thread in current thread?

In this example you’ll see how to obtain the number of active thread in the current thread. You can use the Thread.activeCount() method to get this information. package org.kodejava.lang; public class CountActiveThread { public static void main(String[] args) { Thread t = new Thread(() -> System.out.println("Hello…")); t.start(); // Get the number of active threads in […]

DWayan · 14 Agt 2011 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

In this example you’ll see how to obtain the number of active thread in the current thread. You can use the Thread.activeCount() method to get this information.

package org.kodejava.lang;

public class CountActiveThread {
    public static void main(String[] args) {
        Thread t = new Thread(() -> System.out.println("Hello..."));
        t.start();

        // Get the number of active threads in the current thread's
        // thread group.
        int activeThread = Thread.activeCount();
        System.out.format("Number of active threads of %s is %d %n",
                Thread.currentThread().getName(), activeThread);
    }
}
← Jelajahi catatan lainnya