利用Semaphore模拟多线程处理业务实现动态修改线程数
注意:自用笔记未经严格测试
package xin.ruo.xiang.yang.semaphore;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Semaphore;
/**
* @author: xinruoxiangyang9010
* 使用多线程处理业务逻辑时,动态修改线程数量
*/
@Slf4j
public class SemaphoreTest {
// 设置出初始化要使用的线程数
private static int threadIntiCount = 5;
public static void main(String[] args) throws InterruptedException {
SemaphoreTest semaphoreTest = new SemaphoreTest();
semaphoreTest.businessMethod(threadIntiCount);