Java学习之线程的基本信息

来源:互联网 发布:数据库数据处理 编辑:程序博客网 时间:2024/06/06 11:22

线程的基本信息:


isAlive():判断线程是否还“活”着,即线程是否还未终止
getPriority():获得线程的优先级数值
setPriority():设置线程的优先级数值
setName():给一个线程取名字
getName():给一个线程取名字
currentThread():取得当前正在运行的线程对象也就是取得自己本身。

优先级:

Thread.MAX_PRIORITY:10

Thread.NORM_PRIORITY:5

Thread.MIN_PRIORITY:1

public static void main(String[] args){Thread.currentThread().setName("test1");//名字Thread.currentThread().setPriority(Thread.MAX_PRIORITY);//优先级:概率,不是绝对的优先级Thread.currentThread().setPriority(Thread.MIN_PRIORITY);System.out.println(Thread.currentThread().getName());System.out.println(Thread.currentThread().isAlive());System.out.println(Thread.currentThread().getPriority());}


0 0
原创粉丝点击