private MonoGet (String id) {
Return Mono. Just (id). FlatMap (s - & gt; {
Try {
The info (" sleep thread ");
Thread.sleep (100000);
} the catch (Exception e) {
The info (" error is {} ", e);
}
Return Mono. Just (" u ");
});
}
Public static void main (String [] args) {
T=new testMain testMain ();
MonoObservables=t.g et (" id "). The timeout (Duration. OfMillis (10));
The info (" convert ");
CompletableFutureResult=observables. ToFuture (.) handleAsync ((x, th) - & gt; {
If (th!=null) {
The log. The error (" cache have error is {} ", th);
return null;
}
Return the x;
});
}
As above the following code example, encapsulated in the get method synchronization method for mono, expected after 10 ms, CompletableFuture immediately processing timeout exception, but in fact CompletableFuture part will have to wait until the thread block after the 100 s, to enter, is this why
CodePudding user response:
You set up a thread to sleep 100 s, in the call t.g et (" id ") method have been in this thread, etc., are not returned by the Mono objects to call a timeout (Duration. OfMillis (10)) function, who is to judge the timeoutCodePudding user response: