JAVA-多线程1
继承Thread类
package java.lang;
public class Thread implements Runnable {}
使用方法
class Chef extends Thread {
@Override
public void run() {
//TODO
}
}
public static void main(String[] args) {
Chef chef = new Chef();
chef.start();
}
实现Runnable接口
package java.lang;
public interface Runnable {
void run();
}
使用方法
class Chef2 implements Runnable {
@Override
public void run() {
//TODO
}
}
public static void main(String[] args) {
Thread t = new Thread(new Chef2());
t.start();
}
相关概念
- 程序
- 进程
- 线程
单核CPU的多线程 vs 多核CPU的多线程

浙公网安备 33010602011771号