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?
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With