多线程处理业务逻辑

多线程处理业务逻辑思路:

多线程处理业务逻辑_第1张图片


代码实例:

final CountDownLatch latch = new CountDownLatch(2);
		ExecutorService threadPool = Executors.newFixedThreadPool(2);
		Callable c = new Callable() {
			public Integer call() throws Exception {
				latch.countDown();
				return jbosskucunMapper.countByMaper(map);
			}
		};
		Callable cc = new Callable() {
			public Integer call() throws Exception {
				latch.countDown();
				return userEvaluateMapper.countByExample(example);
			}
		};
		try {
			Cailiaochanp = threadPool.submit(c).get();
			Userchanpcount = threadPool.submit(cc).get();
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}



你可能感兴趣的:(多线程处理业务逻辑)