Skip to content

Commit 6ece930

Browse files
committed
Use put() instead of add()
While add() throws an IllegalStateException if the Queue is full, a put() just waits until there is space left in Queue. - add "return" The usage of "return" is encouraged to make sure to stop a thread when it's interrupted. See hbz/lobid-resources#980.
1 parent eb1cb22 commit 6ece930

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectPipeDecoupler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,17 @@ public <R extends ObjectReceiver<T>> R setReceiver(final R receiver) {
9797

9898
@Override
9999
public void resetStream() {
100-
queue.add(Feeder.BLUE_PILL);
100+
try {
101+
queue.put(Feeder.BLUE_PILL);
102+
} catch (InterruptedException e) {
103+
Thread.currentThread().interrupt();
104+
}
101105
}
102106

103107
@Override
104108
public void closeStream() {
105-
queue.add(Feeder.RED_PILL);
106109
try {
110+
queue.put(Feeder.RED_PILL);
107111
thread.join();
108112
} catch (InterruptedException e) {
109113
Thread.currentThread().interrupt();
@@ -147,6 +151,7 @@ public void run() {
147151
}
148152
} catch (InterruptedException e) {
149153
Thread.currentThread().interrupt();
154+
return;
150155
}
151156
}
152157
}

0 commit comments

Comments
 (0)