When using NetBeans and writing an arbitrary REST endpoint, NetBeans always displays a warning that the method may be converted to asynchronous.
For example, I create the following method:
@GET
@Path("/test")
public String hello() {
return "Hello World!";
}
NetBeans then displays a warning, see below:

Clicking on the tooltip generates this code:
private final ExecutorService executorService = java.util.concurrent.Executors.newCachedThreadPool();
@GET
@Path(value = "/test")
public void hello(@Suspended final AsyncResponse asyncResponse) {
executorService.submit(new Runnable() {
@Override
public void run() {
asyncResponse.resume(doHello());
}
});
}
private String doHello() {
return "Hello World!";
}
The same is true when creating a PUT or POST method. Since NetBeans always shows a warning when implementing a REST endpoint, this tells me that writing synchronous endpoints is considered bad / bad practice. So, should each REST endpoint be asynchronous? What for?
Jakob source
share