简体   繁体   中英

How can we schedule task for 24 hours to get executed and store response in a variable for 24 hours?

I am making post request to an api once in 24 hours and I want to store token received after post request in one variable which am using further.( Token value is valid for 24 hours) I want the same value for 24 hours. Please suggest me an efficient way of implementing this using springboot.

There are various ways you can accomplish this behaviour, but since you want to use Spring, I think you should declare a Bean which will store your token (in a volatile field), while also having a scheduled task for updating it every 24h. I mentioned using a Bean because you can then inject it into other services, so you don't have to resort to using a static field for sharing the value with other services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM