eclipse-ee4j / eclipse-ee4j/jersey

@ManagedExecutorService cause request blocked in JAXRS 2.1 AsyncResponse

Open
#3,706 1 comment 0 reactions 0 assignees View on GitHub
AsyncResponse
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Hi Jersey guys,
I am trying the new features in Java EE 8 and using Glassfish v5, but encountered an issue when used it an asynchronous processing by `AsyncResponse`.

The following codes work well in Java EE 7 /Wildfly, but failed in Java EE8/Glassfish v5, due to timeout.
```java
@Path("async")
@Stateless
public class AsyncResource {

@Resource
private ManagedExecutorService executor;

@Inject
Logger LOG;

@GET
public void getAsync(final @Suspended AsyncResponse res) {
res.setTimeoutHandler(
(ar) -> {
ar.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity("Operation timed out --- please try again.").build());
}
);
res.setTimeout(1000, TimeUnit.MILLISECONDS);
executor.submit(() -> {
//do long run operations.
try {
LOG.log(Level.INFO, " execute long run task in AsyncResource");
//Thread.sleep(new Random().nextInt(1005));
Thread.sleep(500);
} catch (InterruptedException ex) {
LOG.log(Level.SEVERE, "error :" + ex.getMessage());
}
res.resume(Response.ok("asynchronous resource").build());
});
}

}
```

I described this issue in more details on stackoverflow:

https://stackoverflow.com/questions/46830423/how-to-use-managedexecutorservice-with-jaxrs-2-1-asyncresponse-in-java-ee-8-glas

I am not sure this is a Glassfish related issue or jersey issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.