java man调用spring,使用Java函数从Spring引导中调用Spring执行器/重启端点

我想重新启动Spring Boot应用程序,因此使用Spring Actuator / restart端点可以使用curl进行工作,但是我想使用该应用程序内的Java代码来调用相同的函数,我已经尝试过此代码,但是不起作用:

Thread thread = new Thread(new Runnable() {

@Override

public void run() {

RestartEndpoint p = new RestartEndpoint();

p.invoke();

}

});

thread.setDaemon(false);

thread.start();

解决方法:

您需要注入RestartEndPoint:

@Autowired

private RestartEndpoint restartEndpoint;

...

Thread restartThread = new Thread(() -> restartEndpoint.restart());

restartThread.setDaemon(false);

restartThread.start();

即使它会引发异常以通知您这可能会导致内存泄漏,它仍然可以工作:

The web application [xyx] appears to have started a thread named

[Thread-6] but has failed to stop it. This is very likely to create a

memory leak. Stack trace of thread:

>给这个问题/答案的未来读者注意,spring-boot-actuator中不包括RestartEndPoint,您需要添加spring-cloud-context依赖项.

标签:spring-boot-actuator,java,spring,spring-boot,spring-cloud

来源: https://codeday.me/bug/20191014/1912310.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值