public < T > T execute ( long wait , int maxAttempts , Callable < T > callback ) throws Exception { getLog ( ) . debug ( "Waiting for spring application to start..." ) ; for ( int i = 0 ; i < maxAttempts ; i ++ ) { T result = callback . call ( ) ; if ( result != null ) { return result ; } String message = "Spring application is not ready yet, waiting " + wait + "ms (attempt " + ( i + 1 ) + ")" ; getLog ( ) . debug ( message ) ; synchronized ( this . lock ) { try { this . lock . wait ( wait ) ; } catch ( InterruptedException ex ) { Thread . currentThread ( ) . interrupt ( ) ; throw new IllegalStateException ( "Interrupted while waiting for Spring Boot app to start." ) ; } } } throw new MojoExecutionException ( "Spring application did not start before the configured " + "timeout (" + ( wait * maxAttempts ) + "ms" ) ; }
Execute a task retrying it on failure .