本文整理了Java中java.util.concurrent.ForkJoinPool.submit()
方法的一些代码示例,展示了ForkJoinPool.submit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.submit()
方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:submit
暂无
代码示例来源:origin: apache/hbase
@SuppressWarnings("FutureReturnValueIgnored")
synchronized void submit(ForkJoinTask task) {
pool.submit(task);
}
代码示例来源:origin: apache/ignite
/**
* @param grpCtx Group context.
* @param part Local partition.
*/
private Future<Map<PartitionKey, PartitionHashRecord>> calculatePartitionHashAsync(
final CacheGroupContext grpCtx,
final GridDhtLocalPartition part
) {
return ForkJoinPool.commonPool().submit(new Callable<Map<PartitionKey, PartitionHashRecord>>() {
@Override public Map<PartitionKey, PartitionHashRecord> call() throws Exception {
return calculatePartitionHash(grpCtx, part);
}
});
}
代码示例来源:origin: apache/ignite
/**
* @param grpCtx Group context.
* @param part Local partition.
* @param cpFlag Checkpoint flag.
*/
private Future<Map<PartitionKeyV2, PartitionHashRecordV2>> calculatePartitionHashAsync(
final CacheGroupContext grpCtx,
final GridDhtLocalPartition part,
AtomicBoolean cpFlag
) {
return ForkJoinPool.commonPool().submit(() -> calculatePartitionHash(grpCtx, part, cpFlag));
}
代码示例来源:origin: kilim/kilim
public void publish(Runnable task) {
ForkJoinPool current = ForkJoinTask.getPool();
ForkedRunnable fajita = new ForkedRunnable(task);
count.incrementAndGet();
if (current==pool)
fajita.fork();
else
pool.submit(fajita);
}
代码示例来源:origin: OryxProject/oryx
ForkJoinPool pool = new ForkJoinPool(parallelism);
try {
pool.submit(() -> taskIndices.forEach(task::accept)).get();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
代码示例来源:origin: OryxProject/oryx
ForkJoinPool pool = new ForkJoinPool(parallelism);
try {
return pool.submit(() -> taskIndices.mapToObj(task::apply).collect(collector)).get();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
代码示例来源:origin: oracle/opengrok
bySuccess = parallelizer.getForkJoinPool().submit(() ->
args.works.parallelStream().collect(
Collectors.groupingByConcurrent((x) -> {
代码示例来源:origin: apache/hbase
@Override
protected AbstractFSWAL<?> createWAL() throws IOException {
// just like what may do in the WALListeners, schedule an asynchronous task to call the
// getWALs method.
GET_WALS_FUTURE = ForkJoinPool.commonPool().submit(this::getWALs);
// sleep a while to make the getWALs arrive before we return
Threads.sleep(2000);
return Mockito.mock(AbstractFSWAL.class);
}
代码示例来源:origin: apache/kylin
ForkJoinTask rootTask = builderPool.submit(new Runnable() {
@Override
public void run() {
代码示例来源:origin: testcontainers/testcontainers-java
@Test(timeout = 5_000)
public void testThreadSafety() throws Exception {
final int numOfThreads = 3;
CountDownLatch latch = new CountDownLatch(numOfThreads);
AtomicInteger counter = new AtomicInteger();
Future<Integer> lazyFuture = new LazyFuture<Integer>() {
@Override
@SneakyThrows(InterruptedException.class)
protected Integer resolve() {
latch.await();
return counter.incrementAndGet();
}
};
Future<List<Integer>> task = new ForkJoinPool(numOfThreads).submit(() -> {
return IntStream.rangeClosed(1, numOfThreads).parallel().mapToObj(i -> Futures.getUnchecked(lazyFuture)).collect(toList());
});
while (latch.getCount() > 0) {
latch.countDown();
}
assertEquals("All threads receives the same result", Collections.nCopies(numOfThreads, 1), task.get());
}
代码示例来源:origin: apache/kylin
builderPool.submit(new Runnable() {
@Override
public void run() {
代码示例来源:origin: neo4j/neo4j
CountDownLatch txCommitLatch = new CountDownLatch( 1 );
Future<?> result = ForkJoinPool.commonPool().submit( () ->
代码示例来源:origin: apache/hbase
new ReplicationSourceWALReader(fs, CONF, walQueue, 0, getDummyFilter(), source);
reader.start();
Future<WALEntryBatch> future = ForkJoinPool.commonPool().submit(() -> {
return reader.take();
});
代码示例来源:origin: aol/cyclops
default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
return fj.submit(() -> foldParallel(fn)).join();
}
代码示例来源:origin: apache/metron
protected List<Path> writeParallel(Configuration hadoopConfig, Map<Path, List<byte[]>> toWrite,
int parallelism) throws IOException {
List<Path> outFiles = Collections.synchronizedList(new ArrayList<>());
ForkJoinPool tp = new ForkJoinPool(parallelism);
try {
tp.submit(() -> {
toWrite.entrySet().parallelStream().forEach(e -> {
Path path = e.getKey();
List<byte[]> data = e.getValue();
if (data.size() > 0) {
try {
write(getResultsWriter(), hadoopConfig, data, path);
} catch (IOException ioe) {
throw new RuntimeException(
String.format("Failed to write results to path '%s'", path.toString()), ioe);
}
outFiles.add(path);
}
});
}).get();
} catch (InterruptedException | ExecutionException e) {
throw new IOException("Error finalizing results.", e);
} catch (RuntimeException e) {
throw new IOException(e.getMessage(), e.getCause());
}
outFiles.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
return outFiles;
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testSizeIsConsistentAfterRebalanceDuringInsert() throws Exception {
IgniteEx ignite = startGrid(0);
IgniteCache<?, ?> tbl = createTable(ignite);
Future<?> f = null;
for (int i = 0; i < 100; i++) {
if (i == 50)
f = ForkJoinPool.commonPool().submit(() -> startGrid(1));
tbl.query(q("insert into person values(?, ?)").setArgs(i, i));
}
f.get();
awaitPartitionMapExchange();
IgniteCache<?, ?> tbl0 = grid(0).cache("person");
IgniteCache<?, ?> tbl1 = grid(1).cache("person");
assert tbl0.localSize() != 0 && tbl1.localSize() != 0;
assertEquals(100, tbl1.size());
assertEquals(100, tbl0.localSize() + tbl1.localSize());
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
ForkJoinTask<Void> finalizedTask = addReplicaThreadPool.submit(task);
ForkJoinTask<Void> rbwTask = addReplicaThreadPool.submit(task);
代码示例来源:origin: apache/metron
private int getNumberOfBatches(final ReaderSpliterator spliterator) throws ExecutionException, InterruptedException {
final AtomicInteger numSplits = new AtomicInteger(0);
//we want to wrap the spliterator and count the (valid) splits
Spliterator<String> delegatingSpliterator = spy(spliterator);
doAnswer(invocationOnMock -> {
Spliterator<String> ret = spliterator.trySplit();
if(ret != null) {
numSplits.incrementAndGet();
}
return ret;
}).when(delegatingSpliterator).trySplit();
Stream<String> stream = StreamSupport.stream(delegatingSpliterator, true);
//now run it in a parallel pool and do some calculation that doesn't really matter.
ForkJoinPool forkJoinPool = ForkJoinPool.commonPool();
forkJoinPool.submit(() -> {
Map<String, Integer> threads =
stream.parallel().map(s -> Thread.currentThread().getName())
.collect(Collectors.toMap(s -> s, s -> 1, Integer::sum));
Assert.assertTrue(threads.size() > 0);
}
).get();
return numSplits.get();
}
代码示例来源:origin: apache/metron
@Test
public void tlsh_multithread() throws Exception {
//we want to ensure that everything is threadsafe, so we'll spin up some random data
//generate some hashes and then do it all in parallel and make sure it all matches.
Map<Map.Entry<byte[], Map<String, Object>>, String> hashes = new HashMap<>();
Random r = new Random(0);
for(int i = 0;i < 20;++i) {
byte[] d = new byte[256];
r.nextBytes(d);
Map<String, Object> config = new HashMap<String, Object>()
{{
put(TLSHHasher.Config.BUCKET_SIZE.key, r.nextBoolean() ? 128 : 256);
put(TLSHHasher.Config.CHECKSUM.key, r.nextBoolean() ? 1 : 3);
}};
String hash = (String)run("HASH(data, 'tlsh', config)", ImmutableMap.of("config", config, "data", d));
Assert.assertNotNull(hash);
hashes.put(new AbstractMap.SimpleEntry<>(d, config), hash);
}
ForkJoinPool forkJoinPool = new ForkJoinPool(5);
forkJoinPool.submit(() ->
hashes.entrySet().parallelStream().forEach(
kv -> {
Map<String, Object> config = kv.getKey().getValue();
byte[] data = kv.getKey().getKey();
String hash = (String)run("HASH(data, 'tlsh', config)", ImmutableMap.of("config", config, "data", data));
Assert.assertEquals(hash, kv.getValue());
}
)
);
}
代码示例来源:origin: palantir/atlasdb
@Test
public void testCreatingMultipleTablesAtOnce() throws InterruptedException {
int threadCount = 16;
CyclicBarrier barrier = new CyclicBarrier(threadCount);
ForkJoinPool threadPool = new ForkJoinPool(threadCount);
threadPool.submit(() ->
IntStream.range(0, threadCount).parallel().forEach(i -> {
try {
barrier.await();
slowTimeoutKvs.createTable(GOOD_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
} catch (BrokenBarrierException | InterruptedException e) {
// Do nothing
}
}));
threadPool.shutdown();
Preconditions.checkState(threadPool.awaitTermination(90, TimeUnit.SECONDS),
"Not all table creation threads completed within the time limit");
slowTimeoutKvs.dropTable(GOOD_TABLE);
}
内容来源于网络,如有侵权,请联系作者删除!