Jersey Rx client jersey-client-async-executor shutdown - spring-boot

The web application [ROOT] appears to have started a thread named [jersey-client-async-executor-0] but has failed to stop it.
How to gracefully shutdown the jersey-client-async-executor?
This is used with Spring Boot, JerseyRxClient with embedded tomcat.

Jersey Gracefully terminates the thread once the request is complete.
I am using spring boot scheduler to make asynchronous request using rx jersey client.
I had the same doubt as everytime a scheduler runs, jersey client creates new threads incrementing the number.
To be sure that the thread is terminated,
Simple Test:
In your subscriber,
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
this will not list the jersey-client-async-executor-* which was used to make the request.

Related

What are the differences between a tomcat thread and a thread started by the async annotation in spring boot?

I'm learning about threads and how threads work when building a web application.
As per my understanding the flow is as follows:
User sends Http request
Tomcat creates a thread running the controller.
Spring boot runs an async annotated method, that runs code on a seperate thread pool created by the spring boot app.
The tomcat thread is released until the async method is completed to handle more requests.
Am I correct in my understanding?
Does spring boot create its own thread pool to run async operations on freeing the main tomcat thread?
When the asynchronous method is called, the tomcat thread isn't "released" or "freed". It proceeds with the next instruction after the async method call and keeps on going (unless it does something like call get on a future returned by the async method so that it blocks until the future completes). Both threads execute concurrently.
It is true that Spring has its own separate threadpool that it uses for async methods. The Executor used is configurable, #Async takes the name of the executor as an argument so different methods can use different pools if needed. And Tomcat has a pool for its threads, of course.

Quarkus Reactive SQL clients how to make sure my api is reactive

I have a question, I am just starting on reactive programing and I am using quarkus. I made a demo with Panache hibernate reactive and one with SQL clients.
I want each of my rest apis to run on a different non blocking thread. With panache hibernate whenever I did a a blocking action I got a message about it and in the logs it showed me that the api was running o vertex event loop thread so everything was fine.
In Reactive clients everything runs on executor thread 0 does that mean my apis aren’t asynchonus(reactive) from input to output and when I run a blocking action non erros is showing.
Quarkus tries in a lot of places to put the proper guard-rails when it comes to the threads that can be used - however it can't catch all mistakes.
If you are seeing your code executed on a thread that has executor in the name, then the request is being serviced by the wrong thread pool.
If you are using quarkus-resteasy for example, this is the only way that RESTEasy can handle requests - it doesn't matter what your code is, the request is always handled on an executor thread.
For this reason, Quarkus provides RESTEasy Reactive (which is the prefered REST API layer) which allows you to choose whether you want a request to be serviced on an executor thread or an event-loop thread.
See this for more details.

Camel doesn't terminate Java process with max idle seconds property (Spring-Boot)

I have a Spring boot application that uses Apache camel. It is a standalone application that polls a directory with Camel File Component, processes the content and send it Kafka with Camel Kafka Component. I would like the application to be short lived so I want it to self terminate after given idle seconds. I am using camel-spring-boot-starter dependency so I can setup max idle seconds in application properties:
camel.springboot.duration-max-idle-seconds=20
After 20 seconds I see that the camel context and my webserver(used for actuator) are shutdown gracefully but the java process doesn't return an exit code 0. The process hangs like this forever.
Using a similar property, if I set camel.springboot.duration-max-seconds=20 this time, camel context and the web-server shutdown logs are exactly the same and shuts down correctly and the Java process returns an exit code 0, which I was expecting.
Do you happen to run into a similar behavior? Why duration-max-idle-seconds does a graceful shutdown of camel but doesn't terminate the Java process?
I was facing this issue on Camel 3.2.0 and updating to 3.6.0 solves the problem.

Spring boot, Kotlin, Kafka and shutdown

I have a Spring boot / Kotlin application that has a Kafka listener embedded. I am programmatically shutting it down at some point by calling:
configurableApplicationContext.close()
However, Kafka listener does not shut down at that time and instead I get this:
Failed to shut down 1 bean with phase value 2147483547 within timeout of 30000: [org.springframework.kafka.config.internalKafkaListenerEndpointRegistry]
After that, the app shuts down as expected.
What do I need to do differently so it shuts down cleanly when requested?

Graceful shutdown spring boot(After completeing queued requests)

I have a spring boot application running on production server.
Now I want to kill the spring boot application but want to make sure that all the queued requests / requests which are still in processing state gets completed?
So can I achieve this?

Resources