1,使用:

  1. //简化写法:
  2. public class Text05 {
  3. public static void main(String[] args) {
  4. //匿名内部类;直接调用start方法启动线程
  5. new Thread(new Runnable() {
  6. @Override
  7. public void run() {
  8. }
  9. }).start();
  10. }
  11. }
  12. //完整写法:
  13. public class Text05 {
  14. public static void main(String[] args) {
  15. Thread thread=new Thread(new Runnable() {
  16. @Override
  17. public void run() {
  18. }
  19. });
  20. thread.start();
  21. }
  22. }
  1. 原因:**Thread**的底层:
  1. //自带一个Runnable接口参数
  2. public Thread(Runnable target) {
  3. init(null, target, "Thread-" + nextThreadNum(), 0);
  4. }