方案1:
private static Semaphore semaphore = null;
private static ExecutorService executorService = null;
@Value("${ai.baidu.maxThread:2}")
public void setMaxThread(Integer maxThread) {
semaphore = new Semaphore(maxThread);
executorService = Executors.newFixedThreadPool(maxThread);
}
方案2:
public class TestInitializingBean implements InitializingBean{
@Value("${ai.baidu.maxThread:2}")
private Integer maxThread;
private static Semaphore semaphore = null;
private static ExecutorService executorService = null;
@Override
public void afterPropertiesSet() throws Exception {
semaphore = new Semaphore(this.maxThread);
executorService = Executors.newFixedThreadPool(this.maxThread);
}
}