This commit is contained in:
Mrhongxing committed 2026-10-04 20:18:29 +08:00
1 parent c8d1a0cfbc
commit 4ca29321d5
4 files changed
+42 -1

No files matched your search

+22 -1
View File
@@ -1,7 +1,28 @@
package com.nowcoder.logistics; package com.nowcoder.logistics;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class aaa { public class aaa {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello, Logistics!"); ExecutorService executor = Executors.newFixedThreadPool(4);
try{
thread thread1 = new thread();
thread1.CreateThread(executor);
thread thread2 = new thread();
thread2.CreateThread(executor);
} catch (Exception e) {
e.printStackTrace();
}finally {
executor.shutdown();
try {
if(!executor.awaitTermination(1, TimeUnit.MINUTES)) {
System.out.println("Waiting for all tasks to finish...");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// System.out.println("Hello, Logistics!");
} }
} }
@@ -0,0 +1,20 @@
package com.nowcoder.logistics;
import java.util.concurrent.ExecutorService;
public class thread {
private int count = 0;
public void CreateThread(ExecutorService executor) {
executor.submit(() -> {
System.out.println("Hello, Logistics!");
while(count < 500) {
System.out.println("Count: " + count);
count++;
try {
Thread.sleep(1000); // Sleep for 1 second
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}
Binary file not shown.
Binary file not shown.