JAVA 并发编程-应用篇

提到java多线程不免有些人会头大。非常多概念都是非常理解可是真正到了实战的时候又是不知道怎样操作了。以下就结合实际项目来说说多线程的应用。


业务需求:

    举例:批量插入10万条用户的相关活动优惠券

    操作方式:使用固定10个大小的线程池来做。并每次处理1000条插入数据


线程类:注实现Callable<Integer>接口的是能得到返回值的线程类

public class InsertBatchThread implements Callable<Integer> {  
  
  
    private int vdate;  
    private int uid;  
    private int count;  
    private FundsInfoMapper fundsInfoMapper;  
    private WmpsDayInterMapper wmpsDayInterMapper;  
    private DataSource dataSource;  
  
  
    public WmpsDayInterMapper getWmpsDayInterMapper() {  
        if (null == wmpsDayInterMapper) {  
            synchronized (this) {  
                if (null == wmpsDayInterMapper) {  
                    wmpsDayInterMapper = SpringContextUtils.getBean("wmpsDayInterMapper");  
                }  
            }  
        }  
        return wmpsDayInterMapper;  
    }  
  
  
    public FundsInfoMapper getProCommFundsInfoMapper() {  
        if (null == fundsInfoMapper) {  
            synchronized (this) {
posted @ 2017-08-02 14:11  lytwajue  阅读(329)  评论(0编辑  收藏  举报