java给线程命名_Java命名线程

java给线程命名

Each thread in Java has its own name which is set by the JVM by default. Although there are many other attributes associated to the thread like: id, priority etc.

Java中的每个线程都有其自己的名称,该名称由JVM默认设置。 尽管还有许多其他与线程相关的属性,例如:id,priority等。

we can get name of a thread by calling getName() method of Thread class. If we wish to set new name of the thread then setName() method can be used. Both methods belongs to Thread class and even we can set name of thread by passing into constructor during creating object. Lets understand by the examples.

我们可以通过调用Thread类的getName()方法来获得线程的名称。 如果我们希望设置线程的新名称,则可以使用setName()方法。 这两个方法都属于Thread类,甚至我们可以在创建对象时通过传递给构造函数来设置线程的名称。 让我们通过示例来理解。

这两种方法的语法如下。 (Syntax of the two methods is given below.)

setName(String name)
getName()

示例:获取线程名称 ( Example: Fetch Thread Name )

lets first fetch the thread name set by the JVM. It is default name so initially we ca

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值