Java 8 ScheduledThreadPoolExecutor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ScheduledThreadPoolExecutor class.

This code example shows how to use the following methods:setRemoveOnCancelPolicy
        return JBossExecutors.protectedScheduledExecutorService(this.executor);
    } 
 
    @Override 
    public void start(StartContext context) {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.threadFactory);
        executor.setRemoveOnCancelPolicy(true);
        this.executor = executor;
    } 
 
    @Override 
    public void stop(StopContext context) {
        this.executor.shutdownNow();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:setCorePoolSize
        this.keepAlive = keepAlive;
    } 
 
    public synchronized void start(final StartContext context) throws StartException {
        ScheduledThreadPoolExecutor scheduledExecutor = new ExecutorImpl(0, threadFactoryValue.getValue());
        scheduledExecutor.setCorePoolSize(maxThreads);
        if(keepAlive != null)
            scheduledExecutor.setKeepAliveTime(keepAlive.getDuration(), keepAlive.getUnit());
        executor = new ManagedScheduledExecutorService(scheduledExecutor);
    } 
 
    public synchronized void stop(final StopContext context) {
        final ManagedScheduledExecutorService executor = getValue();
        this.context = context;
        context.asynchronous();
        executor.internalShutdown();
        this.executor = null;
    } 
 
    public synchronized ManagedScheduledExecutorService getValue() throws IllegalStateException { 
7
CodeRank
This code example shows how to use the following methods:setRemoveOnCancelPolicy
    private static ThreadFactory createThreadFactory() {
        return new JBossThreadFactory(new ThreadGroup(SessionExpirationScheduler.class.getSimpleName()), Boolean.FALSE, null, "%G - %t", null, null, AccessController.doPrivileged(GetAccessControlContextAction.getInstance()));
    } 
 
    private static ScheduledExecutorService createScheduledExecutor(ThreadFactory factory) {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, factory);
        executor.setRemoveOnCancelPolicy(true);
        return executor;
    } 
 
    public SessionExpirationScheduler(Batcher batcher, Remover<String> remover, ScheduledExecutorService executor) {
        this.batcher = batcher;
        this.remover = remover;
        this.executor = executor;
    } 
 
    @Override 
    public void cancel(ImmutableSession session) {
        Future<?> future = this.expirationFutures.remove(session.getId());
        if (future != null) {
7
CodeRank
This code example shows how to use the following methods:shutdown
        return JBossExecutors.protectedScheduledExecutorService((ScheduledExecutorService) executor);
    } 
 
    @Override 
    void internalShutdown() { 
        executor.shutdown();
    } 
 
    @Override 
    public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
       return executor.schedule(command, delay, unit);
    } 
 
    @Override 
    public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
       return executor.schedule(callable, delay, unit);
    } 
 
    @Override 
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
7
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
import java.util.concurrent.TimeUnit; 
 
public class MainActivity extends Activity implements Runnable {
  private static final int PERIOD_SECONDS=1;
  private ScheduledThreadPoolExecutor executor=
      new ScheduledThreadPoolExecutor(1);
  private ProgressBar primary=null;
  private ProgressBar secondary=null;
 
  @Override 
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    primary=(ProgressBar)findViewById(R.id.progressHS);
    secondary=(ProgressBar)findViewById(R.id.progressHS2);
 
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.scheduleAtFixedRate(this, 0, PERIOD_SECONDS,
                                 TimeUnit.SECONDS);
6
CodeRank
This code example shows how to use the following methods:getQueue
  } 
 
  @Override 
  public int getQueuedMessageCount() 
  { 
    return _executorService.getQueue().size();
  } 
 
  @Override 
  public boolean isAlive() 
  { 
    return !_executorService.isShutdown();
  } 
} 
6
CodeRank
This code example shows how to use the following methods:setExecuteExistingDelayedTasksAfterShutdownPolicy
 
  @Override 
  public void onCreate() { 
    super.onCreate(); 
 
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
 
    mgr=(LocationManager)getSystemService(LOCATION_SERVICE);
    mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                               this);
  } 
 
  @Override 
  public void onDestroy() { 
    mgr.removeUpdates(this);
    executor.shutdown();
 
    super.onDestroy(); 
  } 
6
CodeRank
This code example shows how to use the following methods:setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy
This code example shows how to use the following methods:setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
 
public class ConcurrentUtil { 
    public static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor() {
        ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(1,
            new ThreadFactory() {
                @Override public Thread newThread(Runnable r) {
                    Thread t = Executors.defaultThreadFactory().newThread(r);
                    t.setDaemon(true);
                    return t;
                } 
            }); 
        stpe.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        stpe.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
        return stpe;
    } 
} 
6
CodeRank

Related Java 8 ScheduledThreadPoolExecutor Questions & Answers:

See Code Examples for Java 8 ScheduledThreadPoolExecutor Methods: