Home > Blockchain >  Java Spring - How can I make an HTTP request that checks if a DB entry exists
Java Spring - How can I make an HTTP request that checks if a DB entry exists

Time:12-27

I have a Spring Boot application connected to a PostgreSQL database.

This server will be receiving HTTP requests such as POST from another software to store some statistics, but I want to avoid having to undergo the process of acquiring all of those statistics again if an entry that matches some of the identifiers that the statistics has already exists in the database.

How can I do this check from the software-side, instead of server-side?

That is, without an usual GET method, because that will possibly return a very large list, to the point where it becomes too expensive to find a matching entry and to make this check in the application.

CodePudding user response:

I hope I understood you correctly!

There are several options to launch some functionality without waiting for external requests. One option is to use the @Scheduled functionality of spring

@Configuration
@EnableScheduling
public class SpringConfig {
    ...
}

@Scheduled(fixedDelay = 1000)
public void scheduleFixedDelayTask() {
    daoSevice.execute();
}

https://www.baeldung.com/spring-scheduled-tasks

Good luck!

  • Related