public class Test {
public static void main(String[] args) {
Thread t3 = new Thread(new TestRunnable(),“t-1”); //参数二设置线程名称
t3.start();
System.out.println("-----------------1----------------------");
System.out.println("-----------------2----------------------");
System.out.println("-----------------3----------------------");
}
}
package Thread;

/**

  • 通过实现Runnable接口方式实现多线程
    */
    public class TestRunnable implements Runnable{
    @Override
    public void run() {
    //Thread.currentThread().getName() 获取线程的名字
    System.out.println(Thread.currentThread().getName()+“Runnable多线程运行的代码”);
    for (int i = 0; i <5 ; i++) {
    System.out.println(Thread.currentThread().getName()+“Runnable多线程的逻辑代码”+i);
    }
    }
    }