1、获取线程名称、修改线程名称
Thread thread = Thread.currentThread();
System.out.println(thread);
System.out.println(thread.getName());
thread.setName("王睿");
System.out.println(thread);
System.out.println(thread.getName());
2、线程的优先级
Thread thread = new Thread();
int priority = thread.getPriority();
System.out.println(priority);
thread.setPriority(Thread.MAX_PRIORITY);
priority = thread.getPriority();
System.out.println(priority);
3、线程的休眠
System.out.println("睡眠前:" + LocalDateTime.now());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("睡眠后:" + LocalDateTime.now());
System.out.println("睡眠前:" + LocalDateTime.now());
try {
Thread.sleep(1000,999999);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("睡眠后:" + LocalDateTime.now());