當前位置: 首頁>>代碼示例>>Java>>正文


Java Executors.newWorkStealingPool方法代碼示例

本文整理匯總了Java中java.util.concurrent.Executors.newWorkStealingPool方法的典型用法代碼示例。如果您正苦於以下問題:Java Executors.newWorkStealingPool方法的具體用法?Java Executors.newWorkStealingPool怎麽用?Java Executors.newWorkStealingPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.Executors的用法示例。


在下文中一共展示了Executors.newWorkStealingPool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getExecutorService

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public static ExecutorService getExecutorService(InternalOptions options) {
  if (options.numberOfThreads == options.NOT_SPECIFIED) {
    // This heuristic is based on measurements on a 32 core (hyper-threaded) machine.
    int threads = Integer.min(Runtime.getRuntime().availableProcessors(), 16) / 2;
    return Executors.newWorkStealingPool(threads);
  } else if (options.numberOfThreads == 1) {
    return Executors.newSingleThreadExecutor();
  } else {
    return Executors.newWorkStealingPool(options.numberOfThreads);
  }
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:12,代碼來源:ThreadUtils.java

示例2: test4

import java.util.concurrent.Executors; //導入方法依賴的package包/類
private static void test4() throws InterruptedException {
    ExecutorService executor = Executors.newWorkStealingPool();

    List<Callable<String>> callables = Arrays.asList(
            () -> "task1",
            () -> "task2",
            () -> "task3");

    executor.invokeAll(callables)
            .stream()
            .map(future -> {
                try {
                    return future.get();
                }
                catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            })
            .forEach(System.out::println);

    executor.shutdown();
}
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:23,代碼來源:Executors3.java

示例3: start

import java.util.concurrent.Executors; //導入方法依賴的package包/類
@Override
public void start() {
    if (_workers == -1) {
        this.service = Executors.newCachedThreadPool();
    } else {
        this.service = Executors.newWorkStealingPool(_workers);
    }
}
 
開發者ID:datathings,項目名稱:greycat,代碼行數:9,代碼來源:ExecutorScheduler.java

示例4: testRun2Dir

import java.util.concurrent.Executors; //導入方法依賴的package包/類
@Test
public void testRun2Dir() throws IOException, CompilationException, ProguardRuleParserException {
  Path out = temp.newFolder("outdex").toPath();
  ExecutorService executor = Executors.newWorkStealingPool(2);
  try {
    R8.run(getCommand(out), executor);
  } finally {
    executor.shutdown();
  }
  Assert.assertTrue(Files.isRegularFile(out.resolve(FileUtils.DEFAULT_DEX_FILENAME)));
  Assert.assertTrue(Files.isRegularFile(testFlags.getParent().resolve(MAPPING)));
  Assert.assertTrue(Files.isRegularFile(testFlags.getParent().resolve(SEEDS)));
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:14,代碼來源:R8EntryPointTests.java

示例5: testRun2Zip

import java.util.concurrent.Executors; //導入方法依賴的package包/類
@Test
public void testRun2Zip() throws IOException, CompilationException, ProguardRuleParserException {
  Path out = temp.newFolder("outdex").toPath().resolve("dex.zip");
  ExecutorService executor = Executors.newWorkStealingPool(2);
  try {
    R8.run(getCommand(out), executor);
  } finally {
    executor.shutdown();
  }
  Assert.assertTrue(Files.isRegularFile(out));
  Assert.assertTrue(Files.isRegularFile(testFlags.getParent().resolve(MAPPING)));
  Assert.assertTrue(Files.isRegularFile(testFlags.getParent().resolve(SEEDS)));
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:14,代碼來源:R8EntryPointTests.java

示例6: explore

import java.util.concurrent.Executors; //導入方法依賴的package包/類
/**
 * Gather ResourceSync Framework documents from a source in ResultIndexes.
 *
 * @param url the starting url to explore
 * @return List of resultIndexes of the exploration
 * @throws URISyntaxException if the url could not be converted to a URI.
 * @throws InterruptedException at Executor interrupts.
 */
public List<ResultIndex> explore(String url) throws URISyntaxException, InterruptedException {
  URI uri = new URI(url);

  ExecutorService executor = Executors.newWorkStealingPool();

  List<Callable<ResultIndex>> callables = new ArrayList<>();
  callables.add(() -> exploreWellKnown(uri));
  callables.add(() -> exploreLinks(uri));
  callables.add(() -> exploreRobotsTxt(uri));
  callables.add(() -> exploreRsDocumentUri(uri));

  return executor.invokeAll(callables)
    .stream()
    .map(future -> {
      try {
        return future.get();
      } catch (Exception e) {
        throw new IllegalStateException(e);
      }
    })
    .collect(Collectors.toList());
}
 
開發者ID:EHRI,項目名稱:rs-aggregator,代碼行數:31,代碼來源:Expedition.java

示例7: AffinityMetric

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public AffinityMetric(AffinityMetricConfiguration<LabelType> affinityMetricConfiguration) {
    maximalAffinity = affinityMetricConfiguration.getMaximalAffinity();
    levelOfParallelism = affinityMetricConfiguration.getLevelOfParallelism();
    executorService = (levelOfParallelism == -1) ? Executors.newWorkStealingPool() : Executors.newWorkStealingPool(levelOfParallelism);
    representationSchemeType = affinityMetricConfiguration.getRepresentationSchemeType();
    atomFilter = affinityMetricConfiguration.getAtomFilterType().getFilter();
    alignWithinClusters = affinityMetricConfiguration.isAlignWithinClusters();

    affinityItemsets = new HashMap<>();
}
 
開發者ID:enauz,項目名稱:mmm,代碼行數:11,代碼來源:AffinityMetric.java

示例8: AdherenceMetric

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public AdherenceMetric(List<DataPoint<LabelType>> dataPoints, AdherenceMetricConfiguration<LabelType> adherenceMetricConfiguration) {
    super(dataPoints, adherenceMetricConfiguration.getRepresentationSchemeType());
    distributions = Collections.synchronizedMap(new HashMap<>());
    desiredSquaredExtent = adherenceMetricConfiguration.getDesiredExtent() * adherenceMetricConfiguration.getDesiredExtent();
    squaredExtentDelta = adherenceMetricConfiguration.getDesiredExtentDelta() * adherenceMetricConfiguration.getDesiredExtentDelta();
    maximalAdherence = adherenceMetricConfiguration.getMaximalAdherence();
    vertexOne = adherenceMetricConfiguration.isVertexOne();
    levelOfParallelism = adherenceMetricConfiguration.getLevelOfParallelism();
    executorService = (levelOfParallelism == -1) ? Executors.newWorkStealingPool() : Executors.newWorkStealingPool(levelOfParallelism);
}
 
開發者ID:enauz,項目名稱:mmm,代碼行數:11,代碼來源:AdherenceMetric.java

示例9: ConsensusMetric

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public ConsensusMetric(ConsensusMetricConfiguration<LabelType> consensusMetricConfiguration) {
    maximalConsensus = consensusMetricConfiguration.getMaximalConsensus();
    clusterCutoff = consensusMetricConfiguration.getClusterCutoffValue();
    levelOfParallelism = consensusMetricConfiguration.getLevelOfParallelism();
    executorService = (levelOfParallelism == -1) ? Executors.newWorkStealingPool() : Executors.newWorkStealingPool(levelOfParallelism);
    atomFilter = consensusMetricConfiguration.getAtomFilterType().getFilter();
    representationSchemeType = consensusMetricConfiguration.getRepresentationSchemeType();
    alignWithinClusters = consensusMetricConfiguration.isAlignWithinClusters();

    distributions = new HashMap<>();
    clusteredItemsets = new HashMap<>();
}
 
開發者ID:enauz,項目名稱:mmm,代碼行數:13,代碼來源:ConsensusMetric.java

示例10: CohesionMetric

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public CohesionMetric(List<DataPoint<LabelType>> dataPoints, CohesionMetricConfiguration<LabelType> cohesionMetricConfiguration) {
    super(dataPoints, cohesionMetricConfiguration.getRepresentationSchemeType());
    distributions = new HashMap<>();
    maximalCohesion = cohesionMetricConfiguration.getMaximalCohesion();
    vertexOne = cohesionMetricConfiguration.isVertexOne();
    levelOfParallelism = cohesionMetricConfiguration.getLevelOfParallelism();
    executorService = (levelOfParallelism == -1) ? Executors.newWorkStealingPool() : Executors.newWorkStealingPool(levelOfParallelism);
}
 
開發者ID:enauz,項目名稱:mmm,代碼行數:9,代碼來源:CohesionMetric.java

示例11: ScrapeJob

import java.util.concurrent.Executors; //導入方法依賴的package包/類
/**
 * @param layerUrl Does not include "/query" appended to end of url to layer.
 */
public ScrapeJob(String layerUrl) {
  executor = Executors.newWorkStealingPool();
  current = new AtomicInteger();
  total = new AtomicInteger();
  failed = new AtomicBoolean( false);
  this.layerUrl = layerUrl ;
  this.queryUrlStr = layerUrl + "/query";
  this.layerName = getLayerName();
  this.outputFileBase =  OUTPUT_FOLDER + "/" + layerName;
  this.outputZip =  OUTPUT_FOLDER + "/" + layerName + ".zip";
  this.deleteQueue = new ConcurrentLinkedDeque<>();
}
 
開發者ID:mchaynes,項目名稱:northpine,代碼行數:16,代碼來源:ScrapeJob.java

示例12: checkIntegrity

import java.util.concurrent.Executors; //導入方法依賴的package包/類
/**
 * Utility method which check if some objects collides and merge then in that case.
 * @return The number of object that was merged during this check.
 */
private int checkIntegrity()
{
    ExecutorService taskExecutor = Executors.newWorkStealingPool();
    Map<GameObject, Collection<GameObject>> collisions = calculateCollisions(taskExecutor);
    taskExecutor.shutdown();
    try{
        taskExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException ignored) {
        ignored.printStackTrace();
    }
    int i = 0;
    for(Map.Entry<GameObject, Collection<GameObject>> entry : collisions.entrySet())
    {
        GameObject a = entry.getKey();
        Collection<GameObject> collides = entry.getValue();
        for(GameObject b : collides)
        {
            i++;
            collisions.get(b).remove(a);

            a.applyCollide(b);
            GameObjectLibrary.mergeAsteroid(a, b);
            removeGameObject(b);
        }
    }
    return i;
}
 
開發者ID:Silvanosky,項目名稱:StellarCrush,代碼行數:32,代碼來源:GameState.java

示例13: test5

import java.util.concurrent.Executors; //導入方法依賴的package包/類
private static void test5() throws InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newWorkStealingPool();

    List<Callable<String>> callables = Arrays.asList(
            callable("task1", 2),
            callable("task2", 1),
            callable("task3", 3));

    String result = executor.invokeAny(callables);
    System.out.println(result);

    executor.shutdown();
}
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:14,代碼來源:Executors3.java

示例14: run

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public DexProgramClass run() throws Exception {
  // Setup output directory (or write to a temp dir).
  Path output;
  if (options.output != null) {
    output = options.output.toPath();
  } else {
    File temp = File.createTempFile("bisect", "", new File("/tmp"));
    temp.delete();
    temp.mkdir();
    output = temp.toPath();
  }

  ExecutorService executor = Executors.newWorkStealingPool();
  try {
    DexApplication goodApp = readApp(options.goodBuild, executor);
    DexApplication badApp = readApp(options.badBuild, executor);

    File stateFile = options.stateFile != null
        ? options.stateFile
        : output.resolve("bisect.state").toFile();

    // Setup initial (or saved) bisection state.
    BisectState state = new BisectState(goodApp, badApp, stateFile);
    if (options.stateFile != null) {
      state.read();
    }

    // If a "previous" result is supplied on the command line, record it.
    if (options.result != Result.UNKNOWN) {
      state.setPreviousResult(options.result);
    }

    // Setup post-build command.
    Command command = null;
    if (options.command != null) {
      command = (application) -> {
        writeApp(application, output, executor);
        return runCommand(output);
      };
    }

    // Run bisection.
    return run(state, command, output, executor);
  } finally {
    executor.shutdown();
  }
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:48,代碼來源:Bisect.java

示例15: run

import java.util.concurrent.Executors; //導入方法依賴的package包/類
public void run(String... args) throws IOException, InterruptedException
{
    JCommander jc = new JCommander(this);
    jc.parse(args);
    ex = Executors.newWorkStealingPool(Math.max(1, threads));
    if(!alt_output.getPath().equals(""))
        System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(alt_output)), true));
    
    //collect all the files we will be hashing
    List<File> toHash = new ArrayList<>();
    for(File candidate : parameters)
        if(candidate.isFile())
            toHash.add(candidate);
        else if(candidate.isDirectory() && goDeep)
            Files.walk(candidate.toPath()).filter(Files::isRegularFile).forEach(c -> toHash.add(c.toFile()));
    
    if(toCompare)
    {
        if(parameters.size() > 2 || parameters.isEmpty())
            throw new IllegalArgumentException("Can only compare at most two indexes at a time!");
        
        List<int[]> hashesA = new ArrayList<>();
        List<String> filesA = new ArrayList<>();
        
        List<int[]> hashesB = new ArrayList<>();
        List<String> filesB = new ArrayList<>();
        
        readHashesFromFile(parameters.get(0), hashesA, filesA);
        if(parameters.size() == 2)
            readHashesFromFile(parameters.get(1), hashesB, filesB);
        else
        {
            hashesB = hashesA;
            filesB = filesA;
        }
        
        compare(hashesA, filesA, hashesB, filesB);
    }
    else if(genCompare)
        genComp(toHash);
    else
        hashFiles(toHash);
    
    ex.shutdownNow();
}
 
開發者ID:EdwardRaff,項目名稱:jLZJD,代碼行數:46,代碼來源:Main.java


注:本文中的java.util.concurrent.Executors.newWorkStealingPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。