Skip to content

Commit

Permalink
clean up thread when closing connection (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: bwilloughby <[email protected]>
  • Loading branch information
byblakeorriver and byblakeorriver authored Dec 18, 2020
1 parent 9a41e27 commit e9eddf6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data-api/java-websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.coinapi.websocket</groupId>
<artifactId>v1</artifactId>
<version>1.3</version>
<version>1.4</version>

<organization>
<name>COINAPI LTD</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class CoinAPIWebSocketImpl implements CoinAPIWebSocket {
private ClientManager client;
private Optional<Session> connection = Optional.empty();
private Optional<Thread> processingMessages;
private volatile boolean running = true;

private Queue messagesQueue = new LinkedBlockingDeque();

Expand All @@ -52,7 +53,7 @@ public CoinAPIWebSocketImpl(Boolean isSandbox) {
client = ClientManager.createClient();

Runnable task = () -> {
while (true) {
while (running) {
if (messagesQueue.size() > 0) {
String message = (String) messagesQueue.remove();
InputStream stream = new ByteArrayInputStream(message.getBytes());
Expand Down Expand Up @@ -155,6 +156,7 @@ public void closeConnect() throws IOException {
}

if (processingMessages.isPresent() && processingMessages.get().isAlive()) {
running = false;
processingMessages.get().interrupt();
System.out.println("processingMessage thread interrupt");
}
Expand Down

0 comments on commit e9eddf6

Please sign in to comment.