Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f57697

Browse files
authored
Replace AtomicBoolean with volatile boolean field. (#796)
Atomic's are good when you need CAS. If you need only read/write from different threads, volatile is enough.
1 parent 6e94df5 commit 4f57697

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

terminal/src/main/java/org/jline/terminal/impl/PosixPtyTerminal.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.io.PrintWriter;
1616
import java.nio.charset.Charset;
1717
import java.util.Objects;
18-
import java.util.concurrent.atomic.AtomicBoolean;
1918

2019
import org.jline.terminal.spi.Pty;
2120
import org.jline.utils.ClosedException;
@@ -146,23 +145,23 @@ public boolean paused() {
146145
private static class InputStreamWrapper extends NonBlockingInputStream {
147146

148147
private final NonBlockingInputStream in;
149-
private final AtomicBoolean closed = new AtomicBoolean();
148+
private volatile boolean closed;
150149

151150
protected InputStreamWrapper(NonBlockingInputStream in) {
152151
this.in = in;
153152
}
154153

155154
@Override
156155
public int read(long timeout, boolean isPeek) throws IOException {
157-
if (closed.get()) {
156+
if (closed) {
158157
throw new ClosedException();
159158
}
160159
return in.read(timeout, isPeek);
161160
}
162161

163162
@Override
164163
public void close() throws IOException {
165-
closed.set(true);
164+
closed = true;
166165
}
167166
}
168167

0 commit comments

Comments
 (0)