mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	fix 修复 有界队列与优先队列 错误使用问题
This commit is contained in:
		@@ -131,6 +131,32 @@ public class QueueUtils {
 | 
				
			|||||||
        return priorityBlockingQueue.offer(data);
 | 
					        return priorityBlockingQueue.offer(data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 优先队列获取一个队列数据 没有数据返回 null(不支持延迟队列)
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param queueName 队列名
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> T getPriorityQueueObject(String queueName) {
 | 
				
			||||||
 | 
					        RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.poll();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 优先队列删除队列数据(不支持延迟队列)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> boolean removePriorityQueueObject(String queueName, T data) {
 | 
				
			||||||
 | 
					        RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.remove(data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 优先队列销毁队列 所有阻塞监听 报错(不支持延迟队列)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> boolean destroyPriorityQueue(String queueName) {
 | 
				
			||||||
 | 
					        RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.delete();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 尝试设置 有界队列 容量 用于限制数量
 | 
					     * 尝试设置 有界队列 容量 用于限制数量
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -169,6 +195,32 @@ public class QueueUtils {
 | 
				
			|||||||
        return boundedBlockingQueue.offer(data);
 | 
					        return boundedBlockingQueue.offer(data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 有界队列获取一个队列数据 没有数据返回 null(不支持延迟队列)
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param queueName 队列名
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> T getBoundedQueueObject(String queueName) {
 | 
				
			||||||
 | 
					        RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.poll();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 有界队列删除队列数据(不支持延迟队列)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> boolean removeBoundedQueueObject(String queueName, T data) {
 | 
				
			||||||
 | 
					        RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.remove(data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 有界队列销毁队列 所有阻塞监听 报错(不支持延迟队列)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static <T> boolean destroyBoundedQueue(String queueName) {
 | 
				
			||||||
 | 
					        RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
 | 
				
			||||||
 | 
					        return queue.delete();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 订阅阻塞队列(可订阅所有实现类 例如: 延迟 优先 有界 等)
 | 
					     * 订阅阻塞队列(可订阅所有实现类 例如: 延迟 优先 有界 等)
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,7 @@ public class BoundedQueueController {
 | 
				
			|||||||
    @GetMapping("/add")
 | 
					    @GetMapping("/add")
 | 
				
			||||||
    public R<Void> add(String queueName, int capacity) {
 | 
					    public R<Void> add(String queueName, int capacity) {
 | 
				
			||||||
        // 用完了一定要销毁 否则会一直存在
 | 
					        // 用完了一定要销毁 否则会一直存在
 | 
				
			||||||
        boolean b = QueueUtils.destroyQueue(queueName);
 | 
					        boolean b = QueueUtils.destroyBoundedQueue(queueName);
 | 
				
			||||||
        log.info("通道: {} , 删除: {}", queueName, b);
 | 
					        log.info("通道: {} , 删除: {}", queueName, b);
 | 
				
			||||||
        // 初始化设置一次即可
 | 
					        // 初始化设置一次即可
 | 
				
			||||||
        if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
 | 
					        if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
 | 
				
			||||||
@@ -64,7 +64,7 @@ public class BoundedQueueController {
 | 
				
			|||||||
    @GetMapping("/remove")
 | 
					    @GetMapping("/remove")
 | 
				
			||||||
    public R<Void> remove(String queueName) {
 | 
					    public R<Void> remove(String queueName) {
 | 
				
			||||||
        String data = "data-" + 5;
 | 
					        String data = "data-" + 5;
 | 
				
			||||||
        if (QueueUtils.removeQueueObject(queueName, data)) {
 | 
					        if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
 | 
				
			||||||
            log.info("通道: {} , 删除数据: {}", queueName, data);
 | 
					            log.info("通道: {} , 删除数据: {}", queueName, data);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return R.fail("操作失败");
 | 
					            return R.fail("操作失败");
 | 
				
			||||||
@@ -81,7 +81,7 @@ public class BoundedQueueController {
 | 
				
			|||||||
    public R<Void> get(String queueName) {
 | 
					    public R<Void> get(String queueName) {
 | 
				
			||||||
        String data;
 | 
					        String data;
 | 
				
			||||||
        do {
 | 
					        do {
 | 
				
			||||||
            data = QueueUtils.getQueueObject(queueName);
 | 
					            data = QueueUtils.getBoundedQueueObject(queueName);
 | 
				
			||||||
            log.info("通道: {} , 获取数据: {}", queueName, data);
 | 
					            log.info("通道: {} , 获取数据: {}", queueName, data);
 | 
				
			||||||
        } while (data != null);
 | 
					        } while (data != null);
 | 
				
			||||||
        return R.ok("操作成功");
 | 
					        return R.ok("操作成功");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ public class PriorityQueueController {
 | 
				
			|||||||
    @GetMapping("/add")
 | 
					    @GetMapping("/add")
 | 
				
			||||||
    public R<Void> add(String queueName) {
 | 
					    public R<Void> add(String queueName) {
 | 
				
			||||||
        // 用完了一定要销毁 否则会一直存在
 | 
					        // 用完了一定要销毁 否则会一直存在
 | 
				
			||||||
        boolean b = QueueUtils.destroyQueue(queueName);
 | 
					        boolean b = QueueUtils.destroyPriorityQueue(queueName);
 | 
				
			||||||
        log.info("通道: {} , 删除: {}", queueName, b);
 | 
					        log.info("通道: {} , 删除: {}", queueName, b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 0; i < 10; i++) {
 | 
					        for (int i = 0; i < 10; i++) {
 | 
				
			||||||
@@ -63,7 +63,7 @@ public class PriorityQueueController {
 | 
				
			|||||||
        PriorityDemo data = new PriorityDemo();
 | 
					        PriorityDemo data = new PriorityDemo();
 | 
				
			||||||
        data.setName(name);
 | 
					        data.setName(name);
 | 
				
			||||||
        data.setOrderNum(orderNum);
 | 
					        data.setOrderNum(orderNum);
 | 
				
			||||||
        if (QueueUtils.removeQueueObject(queueName, data)) {
 | 
					        if (QueueUtils.removePriorityQueueObject(queueName, data)) {
 | 
				
			||||||
            log.info("通道: {} , 删除数据: {}", queueName, data);
 | 
					            log.info("通道: {} , 删除数据: {}", queueName, data);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return R.fail("操作失败");
 | 
					            return R.fail("操作失败");
 | 
				
			||||||
@@ -80,7 +80,7 @@ public class PriorityQueueController {
 | 
				
			|||||||
    public R<Void> get(String queueName) {
 | 
					    public R<Void> get(String queueName) {
 | 
				
			||||||
        PriorityDemo data;
 | 
					        PriorityDemo data;
 | 
				
			||||||
        do {
 | 
					        do {
 | 
				
			||||||
            data = QueueUtils.getQueueObject(queueName);
 | 
					            data = QueueUtils.getPriorityQueueObject(queueName);
 | 
				
			||||||
            log.info("通道: {} , 获取数据: {}", queueName, data);
 | 
					            log.info("通道: {} , 获取数据: {}", queueName, data);
 | 
				
			||||||
        } while (data != null);
 | 
					        } while (data != null);
 | 
				
			||||||
        return R.ok("操作成功");
 | 
					        return R.ok("操作成功");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user