解決rejected from java.util.concurrent.ThreadPoolExecutor@29e84858
解決方法:
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 50, 30*1000,TimeUnit.MILLISECONDS, new LinkedBlockingDeque<Runnable>(1000));
使用java.util.concurrent.ThreadPoolExecutor.execute(Runnable command)方法提交任務時,當線程池中正在使用的線程數達到了設置的最大的值(50),而且隊列已(1000),就會報錯。
增加判斷即可:executor.getActiveCount()<50時才執行execute方法。