I have a method, which writes to the database. The requirement is to make sure that this method does not execute after a certain time elapses. If it returns before that, the
There is also an AspectJ solution for that with jcabi-aspects library:
@Timeable(limit = 5, unit = TimeUnit.SECONDS) public String writeToDb() { // writeToDb }
There is an article explaining it further: Limit Java Method Execution Time