Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop WildFly 10 programmatically

I am migrating from JBoss 6.1.0_final to WildFly 10. On a certain condition, I want to stop my server. Like:

if (condition == true) 
   System.exit(1);

The above code works fine in JBoss, it shuts down the server immediately. But when I exeute the same in WildFly10, the server does not stop immediately.

It sends the shutdown signal, then unbound datasource then JMX and so on. I found can be done by MBeans but not working here: https://developer.jboss.org/thread/198579. This gives some error like:

params and description have different lengths

I want to stop my WildFly10 server immediately. Any one have done something like this?

like image 715
Hitesh Ghuge Avatar asked Sep 29 '26 00:09

Hitesh Ghuge


1 Answers

The following should work (just handle the exceptions):

MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("jboss.as:management-root=server");
mBeanServer.invoke(objectName, "shutdown", new Object[] { false, 0 }, 
        new String[] { boolean.class.getName(), int.class.getName() });
like image 194
cassiomolin Avatar answered Oct 01 '26 15:10

cassiomolin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!