Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does @Asynchronous have a Timeout

When i call a Method like this:

@Asynchronous
public void cantstopme() {
  for(;;);
}

Would it run forever or would the Application Server kill it after a certain time?

like image 718
Nick Russler Avatar asked Feb 16 '23 01:02

Nick Russler


2 Answers

Every time a method annotated @Asynchronous is invoked by anyone it will immediately return regardless of how long the method actually takes.

Each invocation should return a Future object that essentially starts out empty and will later have its value filled in by the container when the related method call actually completes.

For example:

@Asynchronous
public Future<String> cantstopme() {

}

and then call it this way:

final Future<String> request = cantstopme();

And later you could ask for the result using the Future.get() method with a specific timeout, i.e:

request.get(10, TimeUnit.SECONDS);
like image 180
Eduardo Sanchez-Ros Avatar answered Feb 18 '23 15:02

Eduardo Sanchez-Ros


This code will run forever. AS or standalone app, Java has no legal means to interrupt a thread if the running code is not designed to be interrupted.

like image 36
Evgeniy Dorofeev Avatar answered Feb 18 '23 14:02

Evgeniy Dorofeev