一、线程两种实现方法
1.继承Thread类
2.实现Runnable接口
二、线程操作方法
1.设置和取得名字
* 设置名字
|-set: public final void setName(String name)
|- 构造:
|- public Thread(Runnable target,String name)
|- public Thread(String name)
* 取得名字
|- public final String getName()
* 在线程中因为其不确定性,所以提供了一个方法,可以获取当前的操作线程。
|- public static Thread currentThread()
* 在java执行中一个java程序至少启动两个线程:mian、gc
2.线程的休眠
* Thread.sleep(500); //休眠500毫秒
3.线程的中断
* therad.interrupt();
4.线程优先级
* 最高MAX_PRIORITY
* 中等NORM_PRIORITY
* 最低 MIX_PRIORITY
t.setPriority(Thread.MAX_PRIORITY); //主方法main为中等优先级
关注公众号,观看更多java基础知识。