public class Main {
public static void main(String[] args) {
Thread t = new Thread();
t.start();
System.out.println("启动了一个新的线程");
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
}
}
class MyThread extends Thread {
@Override
public void run() {
System.out.println("start new thread!");
}
}
public class ThreadDemo01 {
public static void main(String[] args) {
Thread t = new Thread(new MyRunnable());
t.start();
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
System.out.println("start new thread!");
}
}
public class ThreadDemo02 {
public static void main(String[] args) {
Thread t = new Thread(() -> {
System.out.println("start new thread!");
});
t.start();//启动新线程
}
}
public class ThreadDemo03 {
public static void main(String[] args) {
System.out.println("main start...");
Thread t = new Thread(() -> {
System.out.println("thread run...");
try {
Thread.sleep(10);
} catch (InterruptedException ignored) {
}
System.out.println("thread end.");
});
t.start();
try {
Thread.sleep(20);
} catch (InterruptedException ignored) {
}
System.out.println("main end...");
}
}