s-day05--多线程的实现方式一
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package com.inmind.thread02;
|
||||||
|
/*
|
||||||
|
在java中使用一个类Thread来表示一个线程.
|
||||||
|
|
||||||
|
启动多线程的方式一:
|
||||||
|
1.定义一个子类继承Thread
|
||||||
|
2.重写run方法
|
||||||
|
3.创建子类对象,调用start方法启动
|
||||||
|
*/
|
||||||
|
public class Demo13 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
MyThread myThread = new MyThread();
|
||||||
|
myThread.start();//启动线程,执行线程任务run()
|
||||||
|
System.out.println("--------");
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
System.out.println("hello java");
|
||||||
|
}
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.inmind.thread02;
|
||||||
|
|
||||||
|
public class MyThread extends Thread{//线程类
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//定义该线程的任务
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
System.out.println("hello JS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user