一.继承Thread类
package com.lnternet.thread;
/**
* 创建多线程的第一种方式:继承java.lang.Thread类
* 创建一个子线程完成1-100的输出.主线程执行同样的操作
* @author LN
*/
//1.创建继承Thread的子类
class SubThread extends Thread{
//2.重写run方法
public void run() {
for (int i = 1; i <= 100; i++) {
System.out.println(Thread.currentThread().getName()+ i);
}
}
}
public class ThreadTest {
public static void main(String[] args) {
//3.创建子线程对象
SubThread subThread = new SubThread();
//4.调用start方法,启动次线程,调用响应run方法
subThread.start();
for (int i = 1; i <= 100; i++) {
System.out.println(Thread.currentThread().getName()+ i);
}
}
}