六、继承Thread类和实现Runnable接口对比(6、 Comparison between inheriting thread class and implementing runnable interface)

  • 子类继承Thread类具备多线程能力启动线程:子类对象. start()
  • 不建议使用:避免OOP单继承局限性
  • 实现接口Runnable具有多线程能力
  • 启动线程:传入目标对象+Thread对象.start()
  • 推荐使用:避免单继承局限性,灵活方便,方便同一个对象被多个线程使用
————————
  • Subclass inherits thread class, which has multithreading ability. Start thread: subclass object  start()
  • Not recommended: avoid the limitation of OOP single inheritance
  • The implementation interface runnable has multithreading capability
  • Start thread: pass in the target object + thread object start()
  • Recommended: it avoids the limitation of single inheritance, is flexible and convenient, and is convenient for the same object to be used by multiple threads