业务场景
调用第三方接口,对方一次最多返回30条数据,想查取更多条数据时,使用多线程多次取值,最后整合数据,获取想要结果集。
Spring 配置线程池
<bean id="queryFlightLowPriceExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数,默认为1-->
<property name="corePoolSize" value="3" />
<!-- 最大线程数,默认为Integer.MAX_VALUE-->
<property name="maxPoolSize" value="20" />
<property name="queueCapacity" value="1000" />
<!-- 线程池维护线程所允许的空闲时间,默认为60s-->
<property name="keepAliveSeconds" value="100" />
</bean>
实现Callable接口
class MyThread implements Callable<String> {//创建一个类 实现Callable接口,Callable的好处是,调用线