Search code examples
javapostgresqlspring-bootasynchronoustomcat8

java Spring boot asynchronous data processing


I have a java spring boot application with a REST-controller that processes HTTP post request and embedded tomcat server. the controller gets events all the time and stores them in a database. I want to implement a process in the same application that checks asynchronously if a certain event has been stored.

how can I implement this please? can I do with a java thread? I am looking for a optimal Way to implement this.

Thank you in advance


Solution

  • If you really need/want to check asynchronously for some events registered when processing a web request, you can use Spring @Scheduled annotation. You may take a look at: https://spring.io/guides/gs/scheduling-tasks/

    Spring boot has the abstraction of task executor (equivalent to a thread pool) in order to execute @Scheduled tasks. You can find valuable information on how to configure the task executor for the @Scheduled annotation here: What is the default scheduler pool size in spring-boot?