Runnable请求没有返回值
继承Runnable的执行类:
class InsertMysql implements Runnable{
private String name;
private String id;
private InsertMysql(String name,String id){
this.name = name;
this.id = id;
}
@Override
public void run() {
aaMapper.insert(name,id);
}
}
线程池submit:
for (User user : AllUser) {
String name = user.getName();
String id = user.getId();
threadPool.submit(new InsertMysql(name,id));
}
配置线程池:
@Autowired
private ThreadPoolTaskExecutor threadPool;
<!-- spring thread pool executor -->
<bean id="threadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 线程池维护线程的最少数量 -->
<property name="corePoolSize" value="100"/>
<!-- 允许的空闲时间 -->
<property name="keepAliveSeconds" value="200"/>
<!-- 线程池维护线程的最大数量 -->
<property name="maxPoolSize" value="200"/>
<!-- 缓存队列 -->
<property name="queueCapacity" value="100"/>
<!-- 对拒绝task的处理策略 -->
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
</property>
</bean>