enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例

enumerate

线程类static int枚举(Thread [] th) (Thread Class static int enumerate(Thread[] th))

  • This method is available in package java.lang.Thread.enumerate(Thread[] th).

    软件包java.lang.Thread.enumerate(Thread [] th)中提供了此方法。

  • This method is used to copy all the active thread of the current threads thread group or its subgroup into the specified array which will be given as an argument in the method.

    此方法用于将当前线程线程组或其子组的所有活动线程复制到指定的数组中,该数组将作为方法中的参数给出。

  • This method is static so this method is accessible with classname too like Thread.enumerate(Thread[] th).

    此方法是静态的,因此也可以使用类名访问此方法,例如Thread.enumerate(Thread [] th) 。

  • The return type of this method is int it returns the number of active threads which will be kept in the given array as an argument in the method.

    此方法的返回类型为int,它返回活动线程的数量,该数量将作为方法的参数保留在给定数组中。

  • This method does raise an exception if access permission denies to the thread.

    如果访问权限拒绝该线程,则此方法会引发异常。

Syntax:

句法:

    static int enumerate(Thread[] th){
}

Parameter(s):

参数:

We pass one array of thread type which will keep all active threads of current threads thread group.

我们传递一个线程类型数组,该数组将保留当前线程线程组的所有活动线程。

Return value:

返回值:

The return type of this method is int, it returns the count of all active threads which will be kept in the array as an argument in the method.

此方法的返回类型为int ,它返回所有活动线程的计数,这些计数将作为方法的参数保留在数组中。

Java程序演示enumerate()方法的示例 (Java program to demonstrate example of enumerate() method)

/*  We will use Thread class methods so we are importing 
the package but it is not mandate because 
it is imported by default
*/
import java.lang.Thread;
public class Enumerate {
public static void main(String[] args) {
// By using currentThread() of Thread class will return 
// a reference of currently executing thread.
Thread th = Thread.currentThread();
// By using setName() method we are setting the name of 
// current executing thread
th.setName("Enumerate Thread");
// By using setPriority() method we are setting the 
// priority of current executing thread
th.setPriority(2);
//Display Current Executing Thread
System.out.println("Currently Executing Thread is :" + th);
int active_thread = Thread.activeCount();
// Display the number of active threads in current threads thread group
System.out.println("The Current active threads is : " + active_thread);
Thread[] thread = new Thread[active_thread];
// active_thread kept in the array
Thread.enumerate(thread);
// Loop for printing active thread if we have more than one thread.
for (int i = 0; i < active_thread; ++i)
System.out.println("Display active threads is " + thread[i]);
}
}

Output

输出量

E:\Programs>javac Enumerate.java
E:\Programs>java Enumerate
Currently Executing Thread is :Thread[Enumerate Thread,2,main]
The Current active threads is : 1
Display active threads is Thread[Enumerate Thread,2,main]

翻译自: https://www.includehelp.com/java/thread-class-static-int-enumerate-thread-th-method-with-example.aspx

enumerate

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546050.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自由职业的前半年,我是如何度过的?

生活中所受的苦&#xff0c;终会以一种形式回归。我是一个后知后觉的人&#xff0c;从 2009 年毕业到现在&#xff0c;已经有 11 年的光景了&#xff0c;参加工作的前几年我从没想过要快速的提升自己的技能&#xff0c;对待工作也没有全力以赴&#xff0c;这样的迷茫和随大流的…

Microsoft Visual C++ Runtime Library 错误解决办法

今天安装软件时&#xff0c;出现“Microsoft Visual C Runtime Library”错误&#xff0c;网上查了下解决方法&#xff0c;得以解决。现在分享下&#xff0c;给碰到相同问题的朋友。微软官方解释如下&#xff1a;症状在 Microsoft Windows XP 中运行自定义 Microsoft Visual C …

Eucalyptus常用查询命令

前言&#xff1a; Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems &#xff08;Eucalyptus&#xff09; 是一种开源的软件基础结构&#xff0c;用来通过计算集群或工作站群实现弹性的、实用的云计算。它最初是美国加利福尼亚大学 Santa …

the blocks problem(uva 101 or poj 1208)

题目描述见&#xff1a;uva 101 or poj 1208 关键在于彻底理解题目中搬积木的几个命令的含义&#xff0c;见具体分析 如果还不能理解题意&#xff0c;那么找一个正确通过的代码&#xff0c;编译并输入测试数据&#xff0c;查看其每一个命令的执行情况。如我的代码中162行注…

调整灰度图像的大小,而无需在Python中使用任何内置函数

In this program, we will be using two functions of OpenCV-python (cv2) module. Lets see their syntax and descriptions first. 在此程序中&#xff0c;我们将使用OpenCV-python(cv2)模块的两个功能。 首先让我们看看它们的语法和说明。 1) imread():It takes an absolu…

第一章 认识计算机

*(%)^*&!*第一讲 了解计算机基础知识一、计算机的发展历程1、计算机的起源&#xff08;1&#xff09;世界上第一台计算机&#xff1a;1946年诞生&#xff0c;名称为ENIAC。&#xff08;2&#xff09;世界上第一台并行计算机&#xff1a;1950年诞生&#xff0c;名称为EDVAC&…

scoket多线程例子

大体思路&#xff0c;有n台mc&#xff0c;要dump出数据&#xff0c;n台进行对比&#xff0c;看数据是否一致&#xff0c;设计到同时dump的问题&#xff0c;server断发条指令给这n台mc&#xff0c;mc同时去dump把结果返回给server端&#xff0c;server端把这些结果进行对比serve…

csapp bufbomb实验

csapp (《深入理解计算机系统》&#xff09;一书中有一个关于缓冲区溢出的实验&#xff0c;其程序代码如下&#xff1a; /* Bomb program that is solved using a buffer overflow attack */#include <stdio.h> #include <stdlib.h> #include <ctype.h> #in…

漫画:对象是如何被找到的?句柄 OR 直接指针?

小贴士&#xff1a;想要使用并定位 Java 对象&#xff0c;就要用到 Java 虚拟机栈&#xff08;Java Virtual Machine Stack&#xff09;&#xff0c;它描述的是 Java 方法执行的线程内存模型&#xff1a;每个方法被执行的时候&#xff0c;Java 虚拟机都会同步创建一个栈帧&…

在C ++中检查一个数组是否是另一个数组的子数组

Prerequisite: std::equal() function 先决条件&#xff1a; std :: equal()函数 Problem statement: 问题陈述&#xff1a; Check if one array is subarray of another or not. 检查一个数组是否是另一个数组的子数组。 Example: 例&#xff1a; Input 1:Arr1 [3, 4, 5, …

第二章 认识计算机硬件

*(%)^*&!*第一讲 认识计算机主板一、主板的结构1、主板结构分类&#xff08;2&#xff09;AT、Baby-AT型&#xff08;2&#xff09;ATX型&#xff08;3&#xff09;Micro ATX板型&#xff08;4&#xff09;LPX、NLX、Flex ATX板型&#xff08;5&#xff09;EATX、WATX板型&…

IDEA 不为人知的 5 个骚技巧!真香!

工欲善其事&#xff0c;必先利其器&#xff0c;磊哥最近发现了几个特别棒的 IDEA“骚”技巧&#xff0c;已经迫不及待的想要分享给你了&#xff0c;快上车...1.快速补全行末分号使用快捷键 Shfit Ctrl Enter 轻松实现。2.自带的 HTTP 请求工具IDEA 自带了 HTTP 的测试工具&am…

教育编程语言(转)

这是wikipedia上的内容&#xff0c;转载保存&#xff0c;以便以后查阅&#xff0c;英文版见Educational programming language 主要是介绍了一些适合于教育的编程语言&#xff0c;分别适合于不同的个人需求。 详细内容如下&#xff1a; 许多教育性质的程序设计语言都提供建议…

JavaScript | 将十进制转换为十六进制,反之亦然

Sometimes we need to convert an integer value which is in decimal format to the hexadecimal string in JavaScript or need a decimal value from a given hexadecimal string. 有时&#xff0c;我们需要将十进制格式的整数值转换为JavaScript中的十六进制字符串&#xf…

漫画:Integer 竟然有 4 种比较方法?

代码测试public class IntegerTest {public static void main(String[] args) {Integer i1 127;Integer i2 127;System.out.println(i1 i2);Integer i3 128;Integer i4 128;System.out.println(i3 i4);} }以上代码的执行结果为&#xff1a;truefalse首先&#xff0c;当我…

第三章 组装个人计算机

*(%)^*&!*第一讲 选购个人计算机部件1、计算机配件选购的基本原则&#xff08;1&#xff09;组装电脑按需配置&#xff0c;明确电脑使用范围&#xff1b;&#xff08;2&#xff09;衡量装机预算&#xff1b;&#xff08;3&#xff09;衡量整机运行速度。2、电脑配件选购注意…

IP地址的分类——a,b,c 类是怎样划分的

如今的IP网络使用32位地址&#xff0c;以点分十进制表示&#xff0c;如172.16.0.0。地址格式为&#xff1a;IP地址网络地址&#xff0b;主机地址 或 IP地址主机地址&#xff0b;子网地址&#xff0b;主机地址。 IP地址类型 最初设计互联网络时&#xff0c;为了便于寻址以及层次…

《Introduction to Computing Systems: From bits and gates to C and beyond》

很好的一本计算机的入门书&#xff0c;被很多学校采纳作为教材&#xff0c;作者Yale N. Patt 是计算机界的泰斗。中文版名为《计算机系统概论》&#xff08;译者&#xff1a;梁阿磊 , 蒋兴昌, 林凌&#xff09; 书籍首页 (旧版首页 &#xff09; LC-3相关工具 LC-3Help 采…

在数组中查找第k个最大元素_查找数组中每个元素的最近最大邻居

在数组中查找第k个最大元素Problem statement: 问题陈述&#xff1a; Given an array of elements, find the nearest (on the right) greatest element ofeach element in the array. (Nearest greatest means the immediate greatest one on the right side). 给定一个元素数…

6种快速统计代码执行时间的方法,真香!(史上最全)

我们在日常开发中经常需要测试一些代码的执行时间&#xff0c;但又不想使用向 JMH&#xff08;Java Microbenchmark Harness&#xff0c;Java 微基准测试套件&#xff09;这么重的测试框架&#xff0c;所以本文就汇总了一些 Java 中比较常用的执行时间统计方法&#xff0c;总共…