提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.framework.websocket; |
懒 |
2 |
|
|
3 |
import java.util.concurrent.Semaphore; |
|
4 |
import org.slf4j.Logger; |
|
5 |
import org.slf4j.LoggerFactory; |
|
6 |
|
|
7 |
/** |
|
8 |
* 信号量相关处理 |
|
9 |
* |
|
10 |
* @author ruoyi |
|
11 |
*/ |
|
12 |
public class SemaphoreUtils |
|
13 |
{ |
|
14 |
/** |
|
15 |
* SemaphoreUtils 日志控制器 |
|
16 |
*/ |
|
17 |
private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class); |
|
18 |
|
|
19 |
/** |
|
20 |
* 获取信号量 |
|
21 |
* |
|
22 |
* @param semaphore |
|
23 |
* @return |
|
24 |
*/ |
|
25 |
public static boolean tryAcquire(Semaphore semaphore) |
|
26 |
{ |
|
27 |
boolean flag = false; |
|
28 |
|
|
29 |
try |
|
30 |
{ |
|
31 |
flag = semaphore.tryAcquire(); |
|
32 |
} |
|
33 |
catch (Exception e) |
|
34 |
{ |
|
35 |
LOGGER.error("获取信号量异常", e); |
|
36 |
} |
|
37 |
|
|
38 |
return flag; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* 释放信号量 |
|
43 |
* |
|
44 |
* @param semaphore |
|
45 |
*/ |
|
46 |
public static void release(Semaphore semaphore) |
|
47 |
{ |
|
48 |
|
|
49 |
try |
|
50 |
{ |
|
51 |
semaphore.release(); |
|
52 |
} |
|
53 |
catch (Exception e) |
|
54 |
{ |
|
55 |
LOGGER.error("释放信号量异常", e); |
|
56 |
} |
|
57 |
} |
|
58 |
} |