首页>代码>java线程池同步处理实例>/thread/src/luo/common/thread/pool/SyncThreadPool.java
package luo.common.thread.pool;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class SyncThreadPool {
	
	
	public static List<SessionCallable<String>> getSessionCallable(List<String> lists){
		 List<SessionCallable<String>> callables = new LinkedList<SessionCallable<String>>();
		if(null!=lists&&lists.size()>0){
			for (final String str : lists) {
				callables.add(new SessionCallable<String>() {
					@Override
					public String call() throws Exception {
						String temp = str+"luocheng";
						System.err.println("뎠품窟넋:"+Thread.currentThread()+"--뇹잿품돨鑒앴:"+str+"--뇹잿빈돨鑒앴:"+temp);
						return temp;
					}
				});
			}
		}
		return callables;
	}
	
	
	public static <T> List<Future<T>> syncFn(List<SessionCallable<T>> callables){
		try {
			//눼쉔窟넋넥
			ExecutorService threadPool = Executors.newFixedThreadPool(5);
			if(null!=callables&&callables.size()>0){
				List<Future<T>> Futures = threadPool.invokeAll(callables);
				threadPool.shutdown();
				return Futures;
			}
		} catch (InterruptedException e) {
			new RuntimeException("鑒앴속흙窟넋넥뇹잿呵겨",e);
		}
		return null;
	}
}
最近下载更多
2469095052  LV8 2022年5月27日
mylzdy  LV12 2022年5月21日
ts10542  LV9 2021年10月30日
石乐志  LV1 2021年7月17日
尹恒yingying  LV18 2021年4月29日
liuzzz  LV5 2021年4月26日
zhenghongixin4065  LV9 2021年1月23日
w85225864  LV1 2020年8月24日
倪卟懂  LV18 2020年1月21日
lyd19931203  LV21 2019年12月5日
最近浏览更多
woldxy  LV12 2023年8月22日
dixiu000  LV4 2023年4月14日
lyn520  LV3 2023年2月21日
heqian  LV16 2023年1月10日
mylzdy  LV12 2022年5月21日
szf123  LV12 2022年4月22日
一道念  LV10 2022年1月29日
2469095052  LV8 2021年12月29日
ts10542  LV9 2021年10月30日
cc900118  LV17 2021年9月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友