I found this clean approach :
try (Timeout t = Timeout.after(5, TimeUnit.SECONDS)) {
doSomething();
// this thread will self-interrupt if it doesn't reach this line within 5 seconds
} catch (InterruptedException e) {
// thread timed out or was otherwise interrupted
}
source : https://docs.oracle.com/middleware/1221/coherence/java-reference/com/oracle/common/base/Timeout.html