Home > database >  How to set a timeout to a specific service function in Spring Boot?
How to set a timeout to a specific service function in Spring Boot?

Time:02-09

I am creating an app in which some actions in the service need to be asynchronous.

I set the global timeout for 1 minute in the AsyncConfigurer.

This is OK for most of the actions, but in some actions, I need to set a longer timeout. For example in the following service action:

@Async
public Object someLongFunction() {

Can someone tell me how to set a specific timeout for a specific action?

CodePudding user response:

Just change the return type of the function to java.util.concurrent.Future

It has java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit) method that you can leverage to define custom timeout

  •  Tags:  
  • Related