A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

三种形式:
=====================
  1. package com.heima.test;

  2. public class Test3 {

  3.         /**
  4.          * @param args
  5.          */
  6.         public static void main(String[] args) {
  7.                 Thread.currentThread().setName("我是主线程");                                        //主线程
  8.                 System.out.println(Thread.currentThread().getName());
  9.                
  10.                 new Thread(){                                                                                                //线程1,通过Thread()
  11.                         public void run() {
  12.                                 this.setName("haha");
  13.                                 Thread.currentThread().setName("ze..ze");
  14.                                 System.out.println(Thread.currentThread().getName());
  15.                         }
  16.                 }.start();
  17.                
  18.                
  19.                 new Thread(new Runnable() {                                                                        //线程2,通过Ruannable()
  20.                         public void run() {
  21.                                 Thread.currentThread().setName("heihei");
  22.                                 System.out.println(Thread.currentThread().getName());
  23.                         }
  24.                 }).start();
  25.         }
  26.        
  27. }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马