Skip to content

Commit b353c02

Browse files
committed
Use Future.get() instead of tight while loop to reduce CPU usage
1 parent 7e4e447 commit b353c02

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/keepassxc/WindowsConnection.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.nio.file.Path;
1717
import java.nio.file.Paths;
1818
import java.nio.file.StandardOpenOption;
19+
import java.util.concurrent.ExecutionException;
1920
import java.util.concurrent.Future;
2021

2122
public class WindowsConnection extends Connection {
@@ -65,8 +66,11 @@ protected void sendCleartextMessage(String msg) throws IOException {
6566
protected JSONObject getCleartextResponse() {
6667
var raw = new StringBuilder();
6768
long position = 0;
68-
Future<Integer> operation = pipe.read(buffer, position);
69-
while (!operation.isDone());
69+
try {
70+
pipe.read(buffer, position).get();
71+
} catch (InterruptedException | ExecutionException e) {
72+
log.error(e.toString(), e.getCause());
73+
}
7074
buffer.flip();
7175
charsetDecoder.decode(buffer, charBuffer, true);
7276
charBuffer.flip();

0 commit comments

Comments
 (0)