@Asynchronous has a timeout

When I call a method like this:

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

Will it work forever or will the Application Server be able to kill it after a certain time?

+4
source share
2 answers

Each time a method annotated by @Asynchronous is called by someone, it immediately returns no matter how long the method actually takes.

Each call should return a Future object, which essentially starts empty and will later have its value filled by the container when the call to the corresponding method actually ends.

For instance:

 @Asynchronous public Future<String> cantstopme() { } 

and then name it like this:

 final Future<String> request = cantstopme(); 

And later, you can request the result using the Future.get () method with a specific timeout, i.e.

 request.get(10, TimeUnit.SECONDS); 
+5
source

This code will work forever. AS or a stand-alone application, Java does not have the legal means to interrupt a thread unless the working code is intended to interrupt.

+3
source

Source: https://habr.com/ru/post/1489096/


All Articles