Scheduled still running after disable or undeploy my application
<p>I'm having trouble with <strong>ManagedScheduledExecutorService</strong>. If I disable or undeploy my application the scheduler still running. It stops only when I restart the application server.</p>

<p>I'm using <strong>JEE</strong>, Application Server <strong>Wildfly 9</strong> and <strong>Java8</strong>.</p>

<p>The following code below:</p>

<pre><code>package br.com.decarli;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

import javax.annotation.Resource;
import javax.enterprise.concurrent.LastExecution;
import javax.enterprise.concurrent.ManagedScheduledExecutorService;
import javax.enterprise.concurrent.Trigger;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Destroyed;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;

@ApplicationScoped
public class ApplicationSchedulerX {

@Resource( lookup = "java:jboss/ee/concurrency/scheduler/MyScheduler" )
private ManagedScheduledExecutorService timerService;

public void init( @Observes @Initialized( ApplicationScoped.class ) Object o ) {

    timerService.schedule( () -&gt; {

        System.out.println( " Run scheduler... "  );

    }, new Trigger() {

        @Override
        public Date getNextRunTime( LastExecution le, Date date ) {
            return getNextDateBySeconds( 60 );
        }

        @Override
        public boolean skipRun( LastExecution le, Date date ) {
            return false;
        }

    } );

}

private Date getNextDateBySeconds( long seconds ) {
    LocalDateTime ldt = LocalDateTime.now().plusSeconds( seconds );
    return Date.from( ldt.atZone( ZoneId.systemDefault() ).toInstant() );
}

public void destroy( @Observes @Destroyed( ApplicationScoped.class ) Object o ) {
    //TODO error: Lifecycle operation not supported
    //timerService.shutdown();
}
}
</code></pre>

<p>Wildfly 9 scheduler configuration:</p>

<pre><code>&lt;managed-scheduled-executor-service name="MyScheduler" jndi-name="java:jboss/ee/concurrency/scheduler/MyScheduler" hung-task-threshold="50000" long-running-tasks="true" core-threads="4" keepalive-time="500" reject-policy="ABORT"/&gt;
</code></pre>