-
-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Labels
Description
java-stream-player/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Line 121 in d32a46a
private Future<Void> future; |
This object is never written, but it's read at a few places.
I think the intention might have been to assign it to the result of
java-stream-player/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Line 577 in d32a46a
streamPlayerExecutorService.submit(this); |
For usages of this future, see
java-stream-player/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Lines 638 to 676 in d32a46a
/** | |
* Await for the termination of StreamPlayerExecutorService Thread | |
*/ | |
private void awaitTermination() { | |
if (future != null && !future.isDone()) { | |
try { | |
// future.get() [Don't use this cause it may hang forever and ever...] | |
// Wait ~1 second and then cancel the future | |
final Thread delay = new Thread(() -> { | |
try { | |
for (int i = 0; i < 50; i++) { | |
if (!future.isDone()) | |
Thread.sleep(20); | |
else | |
break; | |
logger.log(Level.INFO, "StreamPlayer Future is not yet done..."); | |
} | |
} catch (final InterruptedException ex) { | |
Thread.currentThread().interrupt(); | |
logger.log(Level.INFO, ex.getMessage(), ex); | |
} | |
}); | |
// Start the delay Thread | |
delay.start(); | |
// Join until delay Thread is finished | |
delay.join(); | |
} catch (final InterruptedException ex) { | |
Thread.currentThread().interrupt(); | |
logger.log(Level.WARNING, ex.getMessage(), ex); | |
} finally { | |
// Harmless if task already completed | |
future.cancel(true); // interrupt if running | |
} | |
} | |
} |
goxr3plus