All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.leancloud.im.BackgroundThreadpool Maven / Gradle / Ivy

There is a newer version: 8.2.28
Show newest version
package cn.leancloud.im;

import java.util.concurrent.*;

public class BackgroundThreadpool {
  private static final BackgroundThreadpool INSTANCE = new BackgroundThreadpool();
  private ThreadPoolExecutor executor;
  private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
  public static BackgroundThreadpool getInstance() {
    return INSTANCE;
  }
  private BackgroundThreadpool() {
    this.executor = new ThreadPoolExecutor(1, 2, 10, TimeUnit.SECONDS,
            new LinkedBlockingDeque());
    this.scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
  }

  public void execute(Runnable runnable) {
    this.executor.execute(runnable);
  }
  public void executeDelayed(Runnable runnable, long deleyInSecond) {
    this.scheduledThreadPoolExecutor.schedule(runnable, deleyInSecond, TimeUnit.SECONDS);
  }
  public void removeScheduledTask(Runnable runnable) {
    this.scheduledThreadPoolExecutor.remove(runnable);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy