多线程批量插入数据

  1. 批量插入数据
 /**
     * 批量插入数据
     */
    public void batchInsertData() throws InterruptedException {
        final Integer threadSize = 10;
        Scanner sc = new Scanner(System.in);
        final Long totalSize = 400000 + sc.nextLong();
        Long pageSize = (totalSize%threadSize == 0)?totalSize/threadSize:totalSize/threadSize+1;
        ExecutorService executorService = Executors.newFixedThreadPool(threadSize);
        Set data;
        List list =new ArrayList();
        for (int i =1;i
/**
     * 构造数据
     * @param i
     * @param pageSize
     * @return
     */
    public static Set pageLimitSize(int i,Long pageSize)
    {
        Set set = new HashSet();
        for (int j=0;j<10000;j++)
        {
            set.add(i*10000 + j);
        }
        return set;
    }

2.多线程处理类

package com.lzl.blog.util;

import com.lzl.blog.service.ArticleService;

import java.util.Set;
import java.util.concurrent.Callable;

public class ThreadInsertDataDTO implements Callable {

    private ArticleService articleService;

    private Set set;

    public ArticleService getArticleService() {
        return articleService;
    }

    public Set getSet() {
        return set;
    }

    public ThreadInsertDataDTO(ArticleService articleService, Set set) {
        this.articleService = articleService;
        this.set = set;
    }

    @Override
    public Boolean call() throws Exception {
        if (null != articleService)
        {
            articleService.batchInsertData(set);
        }
        return true;
    }
}

你可能感兴趣的:(多线程批量插入数据)