三种形式:
=====================
- package com.heima.test;
- public class Test3 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- Thread.currentThread().setName("我是主线程"); //主线程
- System.out.println(Thread.currentThread().getName());
-
- new Thread(){ //线程1,通过Thread()
- public void run() {
- this.setName("haha");
- Thread.currentThread().setName("ze..ze");
- System.out.println(Thread.currentThread().getName());
- }
- }.start();
-
-
- new Thread(new Runnable() { //线程2,通过Ruannable()
- public void run() {
- Thread.currentThread().setName("heihei");
- System.out.println(Thread.currentThread().getName());
- }
- }).start();
- }
-
- }
复制代码 |
|