Semaphore
import java.util.concurrent.Semaphore;
public class T {
public static void main(String[] args) {
Semaphore semaphore = new Semaphore(3);
for (int i = 1; i <= 10; i++) {
new Thread(() -> {
try {
semaphore.acquire();
Thread.sleep(2000);
System.out.println(Thread.currentThread().getName() + " ......");
} catch (Exception e) {
} finally {
semaphore.release();
}
}, "线程" + i).start();
}
}
}