Source:
<code>public void execute(OperationContext opContext, ModelNode model) throws OperationFailedException { final AtomicReference<Thread> newThread = new AtomicReference<>(); try { ServiceName name = SubsystemExtension.SERVICE_NAME; ServiceRegistry serviceRegistry = opContext.getServiceRegistry(true); MonitorService service = (MonitorService) serviceRegistry.getRequiredService(name).getValue(); boolean restart = model.get("restart").asBoolean(false); long delay = model.get("delay").asLong(0L); newThread.set(new Thread(new Runnable() { @Override public void run() { if (delay > 0) { try { Thread.sleep(delay); } catch (Exception e) { newThread.get().interrupt(); } } if (restart && service.isMonitorServiceStarted()) { LOGGER.warn("Hawkular Monitor Service restart requested. Will stop and restart it now."); service.stopMonitorService(); } else { LOGGER.warn("Asked to start the Hawkular Monitor service"); } if (!service.isMonitorServiceStarted()) { service.startMonitorService(); } } }, "Hawkular WildFly Agent Operation Start Thread")); newThread.get().setDaemon(true); newThread.get().start(); } catch (ServiceNotFoundException snfe) { throw new OperationFailedException("Cannot restart Hawkular Monitor service - it is disabled", snfe); <START> } catch (Exception e) { <END> throw new OperationFailedException("Cannot restart Hawkular Monitor service", e); } opContext.stepCompleted(); return; }</code><technical_language>put newThread interrupt in wrong spot. want a catch (InterruptedException ie) catch (Exception e). In new catch clause is call newThread.get().interrupt(). interrupt (potentially) interrupt sleep interrupting sleep, simply "return". want thread stop - do taht catching interrupt returning</technical_language>

Target:
public void execute(OperationContext opContext, ModelNode model) throws OperationFailedException { final AtomicReference<Thread> newThread = new AtomicReference<>(); try { ServiceName name = SubsystemExtension.SERVICE_NAME; ServiceRegistry serviceRegistry = opContext.getServiceRegistry(true); MonitorService service = (MonitorService) serviceRegistry.getRequiredService(name).getValue(); final boolean refresh = model.get("refresh").asBoolean(false); final boolean restart = refresh || model.get("restart").asBoolean(false); final long delay = model.get("delay").asLong(0L); final PathAddress address = refresh ? WildflyCompatibilityUtils.getCurrentAddress(opContext, model) : null; final ModelNode config = refresh ? Resource.Tools.readModel(opContext.readResourceFromRoot(address)) : null; final MonitorServiceConfiguration newConfig = refresh ? new MonitorServiceConfigurationBuilder(config, opContext).build() : null; newThread.set(new Thread(new Runnable() { @Override public void run() { try { if (delay > 0) { Thread.sleep(delay); } if (restart) { LOGGER.warnf("Stopping Hawkular Monitor Service now, %s requested.", refresh ? "refresh" : "restart"); service.stopMonitorService(); } if (service.getMonitorServiceStatus() == ServiceStatus.RUNNING) { LOGGER.warn("Skipping Hawkular Monitor Service start, it is already started."); } else { LOGGER.warn("Starting Hawkular Monitor Service now."); service.startMonitorService(newConfig); } } catch (Exception e) { LOGGER.warn("Aborting start of the Hawkular Monitor service: " + e); return; } } }, "Hawkular WildFly Agent Operation Start Thread")); newThread.get().setDaemon(true); newThread.get().start(); } catch (ServiceNotFoundException snfe) { throw new OperationFailedException("Cannot restart Hawkular Monitor service - it is disabled", snfe); } catch (Exception e) { if (newThread.get() != null) { newThread.get().interrupt(); } throw new OperationFailedException("Cannot restart Hawkular Monitor service", e); } opContext.stepCompleted(); return; }