本文主要是介绍Springboot基于健康检查服务预热,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
用于服务启动之后,健康检查完成才会给服务流量
/*** http://localhost:8080/actuator/health* 服务启动后,服务健康状态为DOWN,等待执行完成warmup()之后变为UP** @author batman*/
@Component
public class MyHealthIndicator implements HealthIndicator {public static final AtomicBoolean preheat = new AtomicBoolean(false);public static final AtomicBoolean preheatEnd = new AtomicBoolean(false);public static final AtomicInteger count = new AtomicInteger(0);@Overridepublic Health health() {if (preheat.compareAndSet(false, true)) {warmup();preheatEnd.compareAndSet(false, true);}if (!preheatEnd.get()) {return Health.down().build();}return Health.up().build();}private void warmup() {try {Thread.sleep(5000L);} catch (InterruptedException e) {e.printStackTrace();}}}
这篇关于Springboot基于健康检查服务预热的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!