| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import lombok.Data; |
| | | import org.apache.commons.lang.RandomStringUtils; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除CountDown |
| | | * @param id |
| | | * @param countDownLatch 对象 |
| | | * @param timeout 等待时间 |
| | | */ |
| | | public void remove(String id, CountDownLatch countDownLatch, int timeout) { |
| | | if (countDownLatch == null) { |
| | | return; |
| | | } |
| | | try { |
| | | countDownLatch.await(timeout, TimeUnit.MILLISECONDS); |
| | | if (data != null) { |
| | | data.remove(id); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 没有等待时间的删除 |
| | | * @param id |
| | | */ |
| | | public void remove(String id) { |
| | | if (data != null) { |
| | | data.remove(id); |
| | | } |
| | | } |
| | | |
| | | public CountDownResultUtil createCoutDown(int times) { |
| | | CountDownLatchUtil countDownLatchUtil = new CountDownLatchUtil(); |
| | | CountDownLatch countDownLatch = new CountDownLatch(times); |
| | | //获取一个7位随机数 |
| | | String str = RandomStringUtils.randomAlphanumeric(7); |
| | | countDownLatchUtil.push(str, countDownLatch); |
| | | return new CountDownResultUtil(str, countDownLatch); |
| | | } |
| | | } |