Reputation: 4688
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?
Upvotes: 4
Views: 3388
Reputation: 1827
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);
Upvotes: 5
Reputation: 135992
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.
Upvotes: 3