package com.friend.demo;
import com.wondersgroup.wdls.data.commons.DBUtils;
import com.wondersgroup.wdls.dbinit.DataSourceConfig;
import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Testduoxianc {
    private Integer threadCount=10;
    private ExecutorService threadPool;
    @Test
    public void execute() {
        DataSourceConfig.init();
        threadPool = Executors.newFixedThreadPool(threadCount);
       // String db = ConfigHolder.get("db.connection.url");
        // 锁成功
        try {
            Collection<Callable<Object>> resultb = new LinkedList<>();
            List<String> aaa027s=DBUtils.query("select pid from t_testdxc where zt='0' limit 0,10000",String.class);
            for (String aaa027 : aaa027s){
                //int a = 0;
                //while (a<10){
                    resultb.add(new task1(aaa027));
                 //   a++;
                }
            }
            threadPool.invokeAll(resultb);
        } catch (InterruptedException e1) {
            Thread.currentThread().interrupt();
        }
    }
    private class task1 implements Callable<Object> {
        private String yjjhDTO;
        public task1 (String yjjhDTO){
            this.yjjhDTO = yjjhDTO;
        }
        public Object call() throws Exception {
            try {
                DBUtils.execSql("update t_testdxc set zt='1' where pid=?",yjjhDTO);
            }catch (Exception e){
            }
            return null;
        }
    }
}
java多线程
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- java-multi-thread-ilss Github地址:https://github.com/imyire...
 - 实战Java高并发程序设计(葛一鸣,郭超)读书笔记 获取方式:http://www.java1234.com/a/...
 - 转自 http://blog.csdn.net/ChatHello/article/details/6906097...
 - 概念 进程:进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单...