fix: fixed future.join blocking thread

This commit is contained in:
chuntaojun 2020-05-18 15:45:20 +08:00
parent 5f39cc8d75
commit 5ac48059cb

View File

@ -47,15 +47,14 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
/** /**
* A concrete implementation of CP protocol: JRaft * A concrete implementation of CP protocol: JRaft
* *
* <pre> * <pre>
* *
*
* *
* ProtocolManager * ProtocolManager
* for p in [LogProcessor4CP] * for p in [LogProcessor4CP]
@ -88,7 +87,6 @@ import java.util.function.BiConsumer;
* JRaftServer.start() * JRaftServer.start()
* *
* *
*
* *
* </pre> * </pre>
* *
@ -177,7 +175,8 @@ public class JRaftProtocol
@Override @Override
public Response submit(Log data) throws Exception { public Response submit(Log data) throws Exception {
CompletableFuture<Response> future = submitAsync(data); CompletableFuture<Response> future = submitAsync(data);
return future.get(); // Here you wait for 10 seconds, as long as possible, for the request to complete
return future.get(10_000L, TimeUnit.MILLISECONDS);
} }
@Override @Override