多线程学习

一、线程的创建

1、继承thread类

public class MyThread extends Thread {
@Override
public void run() {
for (int i = 0; i < 200; i++) {
System.out.println("我在学习线程问题1......");
}
}

public static void main(String[] args) {
MyThread myThread = new MyThread();
myThread.start();


for (int i = 0; i < 2000; i++) {
System.out.println("我在学习线程问题");
}
}


}

2、实现runnable接口 无返回值

public class MyThread3 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 200; i++) {
System.out.println("我在学习线程问题1......");
}
}

public static void main(String[] args) {

MyThread3 myThread3 = new MyThread3();
Thread thread = new Thread(myThread3);
thread.start();

for (int i = 0; i < 2000; i++) {
System.out.println("我在学习线程问题");
}
}


}

3、实现callable接口  有返回值

posted @ 2020-07-07 22:02  牛牛171125  阅读(81)  评论(0编辑  收藏  举报