一、线程两种实现方法

    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程序至少启动两个线程:miangc

 

    ​2.线程的休眠

    ​    ​* Thread.sleep(500);    ​//休眠500毫秒

    ​3.线程的中断

    ​    ​* therad.interrupt();

​4.线程优先级

* 最高MAX_PRIORITY

    ​  ​* 中等NORM_PRIORITY

    ​  ​* 最低 MIX_PRIORITY

    ​    t.setPriority(Thread.MAX_PRIORITY);       //主方法main为中等优先级

关注公众号,观看更多java基础知识。

 JAVA线程

相关文章:

  • 2021-05-04
  • 2021-10-26
  • 2021-07-21
猜你喜欢
  • 2021-07-10
  • 2022-12-23
  • 2022-02-06
  • 2021-10-08
  • 2021-08-31
  • 2021-10-18
  • 2021-12-19
  • 2022-01-21
相关资源
相似解决方案