Jakov
Jakov

Reputation: 1009

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

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?

Upvotes: 0

Views: 694

Answers (1)

Nick
Nick

Reputation: 852

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

Upvotes: 2

Related Questions