zoukankan      html  css  js  c++  java
  • 线程池 Future 带返回结果

    package com.aibi.cmdc.bigscreen.action;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.concurrent.Callable;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.Future;
    
    import com.aibi.cmdc.ws.WSConstans;
    import com.aibi.cmdc.ws.WsUtil;
    import com.sun.org.apache.bcel.internal.generic.NEW;
    
    
    
    public class ThreadPool {
    
    	public static  class MyCallable implements Callable{ 
            private String wsClassNmae; 
            private Map<String, String> params = null;
            private List<String> headCodes = null;
            MyCallable(String wsClassNmae,Map<String, String> params,List<String> headCodes) { 
                 this.wsClassNmae = wsClassNmae; 
                 this.params = params;
                 this.headCodes = headCodes;
            } 
    
            @Override 
            public Object call() throws Exception { 
                  return WsUtil.getData(wsClassNmae, params, headCodes, 0);
            } 
    	}
    	/**
    	 * @param args
    	 * @throws Exception 
    	 * @throws InterruptedException 
    	 */
    	public static void main(String[] args) throws InterruptedException, Exception {
    		
    		ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);  
    		 Map<String,String> params = new HashMap<String, String>();
    		 params.put(WSConstans.params_month, "2015-09");
    		 params.put(WSConstans.params_phoneType, "12170001");
    		 List<String> headCodes = new ArrayList<String>();
    		headCodes.add("provinceId");//省份公司
    		headCodes.add("province");//省份公司
    		headCodes.add("channelAlarm");//渠道覆盖率预警
    		headCodes.add("channelBA");//渠道覆盖率
    		headCodes.add("custormCount");//提货客户数
    		headCodes.add("HisCustormCount");//历史提货客户数
    		Callable c1 = new MyCallable(WSConstans.CLASS_NAME_WS00131 , params, headCodes);
    		headCodes.clear();
    		headCodes.add("provinceId");//省份公司
    		headCodes.add("province");//省份公司
    		headCodes.add("alarmValue");//提货占比预警
    		headCodes.add("top10Value");//TOP10 占比
    		headCodes.add("top5Value");//Top5占比
    		Callable c2 = new MyCallable(WSConstans.CLASS_NAME_WS00132 , params, headCodes);
    		headCodes.clear();
    		headCodes.add("provinceId");//省份公司
    		headCodes.add("province");//省份公司
    		headCodes.add("alarmValue");//异常渠道客户预警
    		headCodes.add("alarmCustorm");//异常客户数
    		Callable c3 = new MyCallable(WSConstans.CLASS_NAME_WS00132 , params, headCodes);
    		Future f1 = fixedThreadPool.submit(c1); 
    		Future f2 = fixedThreadPool.submit(c2); 
    		Future f3 = fixedThreadPool.submit(c3); 
    		Object re1 = f1.get();
    		Object re2 = f2.get();
    		Object re3 = f3.get();
    		System.out.println("1111111111");
    		System.out.println(re1.toString());
    		System.out.println("2222222222");
    		System.out.println(re2.toString());	
    		System.out.println("3333333");
    		System.out.println(re3.toString());
    	}
    
    }
    

      

  • 相关阅读:
    2018-2-13-安装-aria2
    ..USERstm32f10x.h(428): error: #67: expected a "}" ADC1_2_IRQn = 18, /*!
    zubax_gnss移植到STM32F407
    ChibiOS/RT移植到STM32F407
    arm-none-eabi/bin/ld: build/com.zubax.gnss.elf section `.text' will not fit in region `flash'
    Traceback (most recent call last): File "../zubax_chibios/tools/make_boot_descriptor.py", line 251
    Eclipse 交叉编译环境
    PX4/Pixhawk uORB
    FreeRTOS 任务创建和删除(静态)
    FreeRTOS 任务创建和删除(动态)
  • 原文地址:https://www.cnblogs.com/clds/p/4921539.html
Copyright © 2011-2022 走看看