Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 60 java ee Its recommended that you use @ Timeout together with @ Asynchronous so that the microservice can be executed in a separate thread and can therefore finish at any time RetryPolicy This feature provides a retry policy to overcome problems with connectivity The @ Retry annotation shown in Listing 6 can be applied at the method level or the class level Method level definitions will override class level definitions if both exist In the given example the maximum retry count is 3 and the maximum duration is 10000 milliseconds which is 10 seconds When the specified duration is exceeded no more retries will be performed regardless of the retry count Listing 6 @ Retry maxRetries 3 maxDuration 10000 public void invokeService invoke an external service RetryPolicy can also be set for an exception as shown in Listing 7 This is a convenient way of handling exceptions while doing work on external resources such as I O processing Listing 7 @ Retry retryOn IOException class public void readFile Fallback This feature provides an alternative way to handle a failed execution It will be invoked once Timeout RetryPolicy or CircuitBreaker has failed according to its contract Fallback definition for a method restricted with a timeout value and its handler implementation are shown in Listing 8 If the execution of the service retrieveAmount method takes more than 3 seconds
You must have JavaScript enabled to view digital editions.