mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 07:31:57 -05:00
22 lines
617 B
Java
22 lines
617 B
Java
package com.study.demo10;
|
|
|
|
public class MultiTaskThread {
|
|
public static void main(String[] args) {
|
|
Runnable task1 = () -> {
|
|
for (int i = 0; i < 3; i++) {
|
|
System.out.println("任务一 - " + Thread.currentThread().getName());
|
|
}
|
|
};
|
|
|
|
Runnable task2 = () -> {
|
|
System.out.println("任务二 - " + Thread.currentThread().getName() + " - 正在处理业务...");
|
|
};
|
|
|
|
Thread thread1 = new Thread(task1, "线程A");
|
|
Thread thread2 = new Thread(task2, "线程B");
|
|
|
|
thread1.start();
|
|
thread2.start();
|
|
}
|
|
}
|