Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

DeferredResult is not making timeout on Weblogic Server

Below solution is working as expected on Tomcat Server -> shortly speaking I am getting 503 status code with custom timeout message after 3 seconds of task processing (Thread sleep). Unfortunately if the same application is deployed on Weblogic Server (12.2.1.4) and the same test case executed I am not getting timeout exception, instead I am getting mixed responses (requestBody equals "sleepMore"): sometimes 200 status with my custom message "Deferred successfully returned" and sometimes I am getting 200 status code with no payload..

Weblogic Server 12.2.1.4

Java 8

org.springframework.boot
spring-boot-starter-parent
2.6.14 (DeferredResult.java)

@PostMapping("/deferred")
DeferredResult<ResponseEntity<Object>> doDeferred(@RequestBody String requestBody) throws InterruptedException {
    final ResponseEntity<Object> timeoutResponse = ResponseEntity.status(503).body("Deferred timeout");
    final DeferredResult<ResponseEntity<Object>> responseEntityDeferredResult = new DeferredResult<ResponseEntity<Object>>(3000L, timeoutResponse);
    if(requestBody == null){
        requestBody = "anything";
    }
    final String finalRequestBody = requestBody;

    if(finalRequestBody.contains("sleep")){
        ForkJoinPool.commonPool().submit(() -> {
            log.info("Processing in separate thread");
            if(finalRequestBody.equals("sleepMore")){
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {

                }
            } else {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {

                }
            }

            log.info("After the sleep execution");
            responseEntityDeferredResult.setResult(ResponseEntity.status(200).body("Deferred successfully returned"));
            log.info("Finished processing in separate thread");
        });
    } else {
        responseEntityDeferredResult.setResult(ResponseEntity.status(200).body("Deferred successfully returned"));
    }

    return responseEntityDeferredResult;
}
Comments
Post Details
Added on Dec 8 2023
8 comments
330 views