标签:nbsp new t 继承 call stat read bsp str override
一、线程的创建
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接口 有返回值
标签:nbsp new t 继承 call stat read bsp str override
原文地址:https://www.cnblogs.com/871212nyl/p/13263594.html