-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
28 changes: 23 additions & 5 deletions
28
concurrency/src/test/java/com/github/kuangcp/queue/use/blocking/QueueChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
package com.github.kuangcp.queue.use.blocking; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* @author Kuangcp | ||
* 2024-06-07 15:09 | ||
*/ | ||
@Data | ||
public class QueueChannel<E> { | ||
|
||
private BlockingQueue<E> queue; | ||
private AtomicBoolean stop = new AtomicBoolean(false); | ||
private final BlockingQueue<E> queue; | ||
private final AtomicBoolean stop = new AtomicBoolean(false); | ||
|
||
public QueueChannel(BlockingQueue<E> queue) { | ||
this.queue = queue; | ||
} | ||
|
||
public void stop() { | ||
this.stop.set(true); | ||
} | ||
|
||
public boolean isRunning() { | ||
return !this.stop.get(); | ||
} | ||
|
||
public E poll(long timeout, TimeUnit unit) throws InterruptedException { | ||
return queue.poll(timeout, unit); | ||
} | ||
|
||
public void put(E e) throws InterruptedException { | ||
queue.put(e); | ||
} | ||
|
||
public boolean add(E e) { | ||
return queue.add(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters