The @Timeout policy

The @Timeout annotation could be applied to a class or method to make sure that an operation doesn't last forever:

@Timeout(200)
public void operationCouldTimeout() {
...
}

In the preceding example, the operation will be stopped should it last more than 200 ms.