@Override
 public SubmitterScheduler makeSubmitterScheduler(int poolSize, boolean prestartIfAvailable) {
   ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(poolSize);
   if (prestartIfAvailable) {
     executor.prestartAllCoreThreads();
   }
   executors.add(executor);
   return new ScheduledExecutorServiceWrapper(executor);
 }
Ejemplo n.º 2
0
 /**
  * To be instantiated by the context. Others should use context.simpleTimer2() instead
  *
  * @since 0.9
  */
 protected SimpleTimer2(I2PAppContext context, String name, boolean prestartAllThreads) {
   _name = name;
   long maxMemory = Runtime.getRuntime().maxMemory();
   if (maxMemory == Long.MAX_VALUE) maxMemory = 96 * 1024 * 1024l;
   _threads =
       (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32 * 1024 * 1024))));
   _executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
   if (prestartAllThreads) _executor.prestartAllCoreThreads();
   // don't bother saving ref to remove hook if somebody else calls stop
   context.addShutdownTask(new Shutdown());
 }
Ejemplo n.º 3
0
 public static ScheduledExecutorService getExecutor(
     ThreadGroup group, String namePrefix, int threadCount, boolean preStart) {
   if (threadCount == 0) {
     threadCount = 1;
   } else if (threadCount < 0) {
     int numCpus = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
     threadCount = Math.abs(threadCount) * numCpus;
   }
   ThreadFactory threadFactory = createThreadFactory(group, namePrefix);
   ScheduledThreadPoolExecutor executor =
       new ScheduledThreadPoolExecutor(threadCount, threadFactory);
   if (preStart) {
     executor.prestartAllCoreThreads();
   }
   return executor;
 }
Ejemplo n.º 4
0
 {
   schedThPoolExec.prestartAllCoreThreads();
   schedThPoolExec.setKeepAliveTime(0, TimeUnit.SECONDS);
 }