自己创建的线程

代码块
package edu.xcdq.demo01;

public class MyThread extends Thread{
public MyThread(String name){
super(name);
}
@Override
public void run() {
System.out.println("自己创建的线程");
System.out.println("线程名字:"+Thread.currentThread().getName());
}
}
/*
1 extends Thread
2 复写run方法
3 调用start方法启动多线程
测试类
package edu.xcdq.demo01;

public class Demo01 {
public static void main(String[] args) {
/* MyThread myThread1=new MyThread("自己定义的线程名007");
myThread1.start();//线程调用
//myThread.run();//普通调用*/
MyThread t1=new MyThread("线程1");
MyThread t2=new MyThread("线程2");
MyThread t3=new MyThread("线程3");
MyThread t4=new MyThread("线程4");
MyThread t5=new MyThread("线程5");
MyThread t6=new MyThread("线程6");
MyThread t7=new MyThread("线程7");
MyThread t8=new MyThread("线程8");
MyThread t9=new MyThread("线程9");
MyThread t10=new MyThread("线程10");
t1.setPriority(1);
t1.setPriority(2);
t1.setPriority(3);
t1.setPriority(4);
t1.setPriority(5);
t1.setPriority(6);
t1.setPriority(7);
t1.setPriority(8);
t1.setPriority(9);
t1.setPriority(10);

    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
    t1.start();
}

}

你可能感兴趣的:(自己创建的线程)