当前位置: 首页>>代码示例>>Java>>正文


Java PriorityScheduler.shutdownNow方法代码示例

本文整理汇总了Java中org.threadly.concurrent.PriorityScheduler.shutdownNow方法的典型用法代码示例。如果您正苦于以下问题:Java PriorityScheduler.shutdownNow方法的具体用法?Java PriorityScheduler.shutdownNow怎么用?Java PriorityScheduler.shutdownNow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.threadly.concurrent.PriorityScheduler的用法示例。


在下文中一共展示了PriorityScheduler.shutdownNow方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResultTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void getResultTest() throws InterruptedException, ExecutionException {
  final String testResult = StringUtils.makeRandomString(5);
  
  PriorityScheduler scheduler = new StrictPriorityScheduler(1);
  try {
    scheduler.schedule(new Runnable() {
      @Override
      public void run() {
        slf.setResult(testResult);
      }
    }, DELAY_TIME);
    
    assertTrue(slf.get() == testResult);
  } finally {
    scheduler.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:SettableListenableFutureTest.java

示例2: getWithTimeoutResultTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void getWithTimeoutResultTest() throws InterruptedException, 
                                              ExecutionException, 
                                              TimeoutException {
  final String testResult = StringUtils.makeRandomString(5);
  
  PriorityScheduler scheduler = new StrictPriorityScheduler(1);
  try {
    scheduler.prestartAllThreads();
    scheduler.schedule(new Runnable() {
      @Override
      public void run() {
        slf.setResult(testResult);
      }
    }, DELAY_TIME);
    
    assertTrue(slf.get(DELAY_TIME + (SLOW_MACHINE ? 2000 : 1000), TimeUnit.MILLISECONDS) == testResult);
  } finally {
    scheduler.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:22,代码来源:SettableListenableFutureTest.java

示例3: listenableFutureTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void listenableFutureTest() {
  PriorityScheduler executor = new StrictPriorityScheduler(1);
  try {
    PrioritySchedulerServiceWrapper wrapper = new PrioritySchedulerServiceWrapper(executor);
    TestRunnable futureListener = new TestRunnable();
    ListenableFuture<?> future = wrapper.submit(DoNothingRunnable.instance());
    future.addListener(futureListener);
    
    futureListener.blockTillFinished(); // throws exception if never called
  } finally {
    executor.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:15,代码来源:PrioritySchedulerServiceWrapperTest.java

示例4: limitTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void limitTest() throws InterruptedException, ExecutionException {
  int rateLimit = 100;
  final AtomicInteger ranPermits = new AtomicInteger();
  PriorityScheduler pse = new StrictPriorityScheduler(32);
  try {
    RateLimiterExecutor rls = new RateLimiterExecutor(pse, rateLimit);
    ListenableFuture<?> lastFuture = null;
    double startTime = Clock.accurateForwardProgressingMillis();
    boolean flip = true;
    for (int i = 0; i < TEST_QTY * 2; i++) {
      final int permit = 5;
      if (flip) {
        lastFuture = rls.submit(permit, new Runnable() {
          @Override
          public void run() {
            ranPermits.addAndGet(permit);
          }
        });
        flip = false;
      } else {
        lastFuture = rls.submit(permit, new Callable<Void>() {
          @Override
          public Void call() {
            ranPermits.addAndGet(permit);
            return null;
          }
        });
        flip = true;
      }
    }
    lastFuture.get();
    long endTime = Clock.accurateForwardProgressingMillis();
    double actualLimit = ranPermits.get() / ((endTime - startTime) / 1000);
    
    assertEquals(rateLimit, actualLimit, SLOW_MACHINE ? 75 : 50);
  } finally {
    pse.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:41,代码来源:RateLimiterExecutorTest.java

示例5: isShutdownTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void isShutdownTest() {
  PriorityScheduler executor = new StrictPriorityScheduler(1);
  try {
    SchedulerServiceLimiter limiter = new SchedulerServiceLimiter(executor, 1);
    
    assertFalse(limiter.isShutdown());
    executor.shutdownNow();
    assertTrue(limiter.isShutdown());
  } finally {
    executor.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:14,代码来源:SchedulerServiceLimiterTest.java

示例6: runListenerExecutorTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void runListenerExecutorTest() {
  PriorityScheduler executor = new StrictPriorityScheduler(1);
  try {
    TestRunnable tr = new TestRunnable();
    onceHelper.runListener(tr, executor, true);
    tr.blockTillFinished();
    
    assertTrue(tr.ranOnce());
    assertTrue(Thread.currentThread() != tr.lastRanThread);
  } finally {
    executor.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:15,代码来源:RunnableListenerHelperTest.java

示例7: limitExecutionPerCycleStressTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void limitExecutionPerCycleStressTest() {
  PriorityScheduler scheduler = new StrictPriorityScheduler(3);
  final AtomicBoolean testComplete = new AtomicBoolean(false);
  try {
    final Integer key1 = 1;
    final Integer key2 = 2;
    Executor singleThreadedExecutor = new ExecutorLimiter(scheduler, 1);
    final KeyDistributedExecutor distributor = new KeyDistributedExecutor(2, singleThreadedExecutor, 2);
    final AtomicInteger waitingTasks = new AtomicInteger();
    final AtomicReference<TestRunnable> lastTestRunnable = new AtomicReference<>();
    scheduler.execute(new Runnable() {  // execute thread to add for key 1
      @Override
      public void run() {
        while (! testComplete.get()) {
          TestRunnable next = new TestRunnable() {
            @Override
            public void handleRunStart() {
              waitingTasks.decrementAndGet();
              
              TestUtils.sleep(20);  // wait to make sure producer is faster than executor
            }
          };
          lastTestRunnable.set(next);
          waitingTasks.incrementAndGet();
          distributor.execute(key1, next);
        }
      }
    });
    
    // block till there is for sure a backup of key1 tasks
    new TestCondition(() -> waitingTasks.get() > 10).blockTillTrue();
    
    TestRunnable key2Runnable = new TestRunnable();
    distributor.execute(key2, key2Runnable);
    TestRunnable lastKey1Runnable = lastTestRunnable.get();
    key2Runnable.blockTillStarted();  // will throw exception if not started
    // verify it ran before the lastKey1Runnable
    assertFalse(lastKey1Runnable.ranOnce());
  } finally {
    testComplete.set(true);
    scheduler.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:45,代码来源:KeyDistributedExecutorTest.java

示例8: shutdown

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Override
public void shutdown() {
  for (PriorityScheduler ps : schedulers) {
    ps.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:7,代码来源:SubmitterSchedulerTaskInterceptorInterfaceTest.java

示例9: limitTest

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
@Test
public void limitTest() throws InterruptedException, ExecutionException {
  Object key = new Object();
  int rateLimit = 100;
  final AtomicInteger ranPermits = new AtomicInteger();
  PriorityScheduler pse = new StrictPriorityScheduler(32);
  try {
    KeyedRateLimiterExecutor krls = new KeyedRateLimiterExecutor(pse, rateLimit);
    ListenableFuture<?> lastFuture = null;
    double startTime = Clock.accurateForwardProgressingMillis();
    boolean flip = true;
    for (int i = 0; i < TEST_QTY * 2; i++) {
      final int permit = 5;
      if (flip) {
        lastFuture = krls.submit(permit, key, new Runnable() {
          @Override
          public void run() {
            ranPermits.addAndGet(permit);
          }
        });
        flip = false;
      } else {
        lastFuture = krls.submit(permit, key, new Callable<Void>() {
          @Override
          public Void call() {
            ranPermits.addAndGet(permit);
            return null;
          }
        });
        flip = true;
      }
    }
    lastFuture.get();
    long endTime = Clock.accurateForwardProgressingMillis();
    double actualLimit = ranPermits.get() / ((endTime - startTime) / 1000);
    
    assertEquals(rateLimit, actualLimit, SLOW_MACHINE ? 75 : 50);
  } finally {
    pse.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:42,代码来源:KeyedRateLimiterExecutorTest.java

示例10: main

import org.threadly.concurrent.PriorityScheduler; //导入方法依赖的package包/类
public static void main(String args[]) {
  if (args.length == 0) {
    System.err.println("Must provide at least one valid path to inspect");
    System.exit(1);
  }
  
  List<File> examineDirectories = new ArrayList<File>(args.length);
  for (String path : args) {
    File toInspectPath = new File(path);
    if (! toInspectPath.exists()) {
      throw new IllegalArgumentException("Path does not exist: " + path);
    } else if (! toInspectPath.isDirectory()) {
      throw new IllegalArgumentException("Path is not a directory: " + path);
    }
    
    examineDirectories.add(toInspectPath);
  }
  
  int threadCount = Runtime.getRuntime().availableProcessors();
  final PriorityScheduler scheduler = new PriorityScheduler(threadCount, TaskPriority.High, 1000, false);
  scheduler.execute(new Runnable() {
    @Override
    public void run() {
      scheduler.prestartAllThreads();
    }
  });
  try {
    FileCrawler fc = new FileCrawler(scheduler);
    
    if (EXCLUDE_HIDDEN) {
      fc.addFilter(new HiddenFileFilter());
    }
    
    FileNameInspector fni = new FileNameInspector();
    fc.addListener(fni);
    
    DuplicateFileInspector dfi = new DuplicateFileInspector();
    fc.addListener(dfi);
    
    // blocks till computation is done
    fc.crawlDirectories(examineDirectories);

    List<File> renameFiles = fni.getNotableFiles();
    String duplicateResult = dfi.getDuplicateAnalysis(scheduler);
    {
      if (! renameFiles.isEmpty()) {
        System.out.println();
        
        System.out.println("Files for possible rename: ");
        Iterator<File> it = renameFiles.iterator();
        while (it.hasNext()) {
          System.out.println(it.next().getAbsolutePath());
        }
      }
    }
    {
      if (! duplicateResult.isEmpty()) {
        if (! renameFiles.isEmpty()) {
          System.out.println();
        }
        System.out.println(duplicateResult);
      }
    }
    
    System.out.println("\nDONE!!");
  } catch (Throwable t) {
    System.err.println("Thrown exception from main thread, shutting down");
    t.printStackTrace(System.err);
    
    scheduler.shutdownNow();
  } finally {
    scheduler.shutdown();
  }
}
 
开发者ID:jentfoo,项目名称:JFileAnalyzer,代码行数:75,代码来源:FileAnalyzer.java


注:本文中的org.threadly.concurrent.PriorityScheduler.shutdownNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。