Thread names with implementing Runnable and extending Thread class

This question already has an answer here:

  • How is default new thread name given in java? 4 answers

  • In the second example, the tp class calls its parent constructor. Since its parent is Thread , the tp object in main + gets the first auto-assigned name ( Thread-0 ).

    You should never rely on the auto-generated name. If a name is important to you, call the Thread constructor that allows you to set your own name.

    +Side note: Don't name Classes and variables with the same name as you introduce ambiguity.

    链接地址: http://www.djcxy.com/p/16394.html

    上一篇: 中断或停止睡眠线程

    下一篇: 带有实现Runnable和扩展Thread类的线程名称