本文整理汇总了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);
}
}
示例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();
}
示例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);
}
}
示例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)));
}
示例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)));
}
示例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());
}
示例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<>();
}
示例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);
}
示例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<>();
}
示例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);
}
示例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<>();
}
示例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;
}
示例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();
}
示例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();
}
}
示例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();
}