|
|
@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
import java.util.concurrent.LinkedBlockingDeque;
|
|
|
|
import java.util.concurrent.LinkedBlockingDeque;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@ -12,26 +13,30 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class ThreadPoolExecutorService implements IThreadPoolExecutorService {
|
|
|
|
public class ThreadPoolExecutorService implements IThreadPoolExecutorService {
|
|
|
|
private ThreadPoolExecutor poolExecutor;
|
|
|
|
private ThreadPoolExecutor poolExecutor;
|
|
|
|
private ThreadPoolExecutor singleExecutor;
|
|
|
|
|
|
|
|
|
|
|
|
private static LinkedBlockingDeque<Runnable> deque = new LinkedBlockingDeque<Runnable>(10000);
|
|
|
|
|
|
|
|
private static ThreadPoolExecutor singleExecutor =new ThreadPoolExecutor(
|
|
|
|
|
|
|
|
5,10000, 20, TimeUnit.SECONDS,deque);;
|
|
|
|
|
|
|
|
|
|
|
|
private Logger logger= LoggerFactory.getLogger(ThreadPoolExecutorService.class);
|
|
|
|
private Logger logger= LoggerFactory.getLogger(ThreadPoolExecutorService.class);
|
|
|
|
public ThreadPoolExecutorService(){
|
|
|
|
public ThreadPoolExecutorService(){
|
|
|
|
LinkedBlockingDeque<Runnable> deque = new LinkedBlockingDeque<Runnable>();
|
|
|
|
ArrayBlockingQueue<Runnable> poolQeque = new ArrayBlockingQueue<Runnable>(10);
|
|
|
|
poolExecutor=new ThreadPoolExecutor(
|
|
|
|
poolExecutor=new ThreadPoolExecutor(
|
|
|
|
4,4, 5, TimeUnit.SECONDS,deque);
|
|
|
|
5,20, 5, TimeUnit.SECONDS,poolQeque);
|
|
|
|
poolExecutor.allowCoreThreadTimeOut(true);
|
|
|
|
poolExecutor.allowCoreThreadTimeOut(true);
|
|
|
|
singleExecutor =new ThreadPoolExecutor(
|
|
|
|
singleExecutor =new ThreadPoolExecutor(
|
|
|
|
1,1, 5, TimeUnit.SECONDS,deque);
|
|
|
|
1,10000, 20, TimeUnit.SECONDS,deque);
|
|
|
|
singleExecutor.allowCoreThreadTimeOut(true);
|
|
|
|
singleExecutor.allowCoreThreadTimeOut(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void singleExecute(Runnable runnable){
|
|
|
|
public void singleExecute(Runnable runnable){
|
|
|
|
singleExecutor.execute(() -> {
|
|
|
|
singleExecutor.execute(() -> {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
Thread.sleep(3000);
|
|
|
|
// Thread.sleep(300);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
runnable.run();
|
|
|
|
runnable.run();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -39,11 +44,11 @@ public class ThreadPoolExecutorService implements IThreadPoolExecutorService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void execute(Runnable runnable){
|
|
|
|
public void execute(Runnable runnable){
|
|
|
|
poolExecutor.execute(() -> {
|
|
|
|
poolExecutor.execute(() -> {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
Thread.sleep(3000);
|
|
|
|
// Thread.sleep(3000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
runnable.run();
|
|
|
|
runnable.run();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|