本文整理了Java中java.util.stream.LongStream.parallel()
方法的一些代码示例,展示了LongStream.parallel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.parallel()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:parallel
暂无
代码示例来源:origin: speedment/speedment
@Override
public LongStream parallel() {
return toStream().parallel();
}
代码示例来源:origin: speedment/speedment
@Override
public LongStream parallel() {
return wrap(stream().parallel());
}
代码示例来源:origin: stackoverflow.com
import java.util.stream.LongStream;
public class ParallelPlay {
public static void main(String[] args) {
System.out.println(parallelSum(100_000_000));
}
public static long parallelSum(long n) {
return LongStream.rangeClosed(1, n).parallel().sum();
}
}
代码示例来源:origin: se.ugli.ugli-commons/ugli-commons
@Override
public LongStream parallel() {
return new LongResourceStream(stream.parallel(), closeOnTerminalOperation, resources);
}
代码示例来源:origin: net.dongliu/commons-lang
@Override
public ExLongStream parallel() {
return ExLongStream.of(stream.parallel());
}
代码示例来源:origin: com.github.robozonky/robozonky-app
public Collection<Investment> complement(final Collection<Investment> investments) {
final Set<Long> idsToComplement = investments.stream().map(Registry::getId).collect(Collectors.toSet());
return storages.get(Category.NEW).complement(idsToComplement)
.parallel()
.mapToObj(id -> tenant.call(z -> z.getInvestment(id)))
.flatMap(i -> i.map(Stream::of).orElse(Stream.empty()))
.collect(Collectors.toList());
}
代码示例来源:origin: RoboZonky/robozonky
public Collection<Investment> complement(final Collection<Investment> investments) {
final Set<Long> idsToComplement = investments.stream().map(Registry::getId).collect(Collectors.toSet());
return storages.get(Category.NEW).complement(idsToComplement)
.parallel()
.mapToObj(id -> tenant.call(z -> z.getInvestment(id)))
.flatMap(i -> i.map(Stream::of).orElse(Stream.empty()))
.collect(Collectors.toList());
}
代码示例来源:origin: com.speedment.runtime/runtime-core
@Override
public LongStream parallel() {
return wrap(stream().parallel());
}
代码示例来源:origin: douglascraigschmidt/LiveLessons
/**
* Print out the results of subtracting the first 100 numbers.
* If @a parallel is true then a parallel stream is used, else a
* sequential stream is used. The results for each of these tests
* will differ since subtraction is not associative.
*/
private static void testDifferenceReduce(boolean parallel) {
LongStream rangeStream = LongStream
.rangeClosed(1, 100);
if (parallel)
rangeStream.parallel();
long difference = rangeStream
.reduce(1L,
(x, y) -> x - y);
System.out.println((parallel ? "Parallel" : "Sequential")
+ " difference of first 100 numbers = "
+ difference);
}
代码示例来源:origin: com.davidbracewell/mango
/**
* <p>Calculates the summary statistics for the values in the given array.</p>
*
* @param values the values to calculate summary statistics over
* @return the summary statistics of the given array
* @throws NullPointerException if the values are null
*/
static EnhancedDoubleStatistics summaryStatistics(@NonNull long... values) {
return LongStream.of(values).parallel().mapToDouble(i -> i).collect(EnhancedDoubleStatistics::new,
EnhancedDoubleStatistics::accept,
EnhancedDoubleStatistics::combine);
}
代码示例来源:origin: douglascraigschmidt/LiveLessons
/**
* Print out the results of summing the first 100 numbers,
* using @a identity as the initial value of the summation. If @a
* parallel is true then a parallel stream is used, else a
* sequential stream is used. When a sequential or parallel
* stream is used with an identity of 0 the results of this test
* will be correct. When a sequential or parallel stream is used
* with an identity of 0, however, results of this test will be
* incorrect.
*/
private static void testSum(long identity,
boolean parallel) {
LongStream rangeStream = LongStream
.rangeClosed(1, 100);
if (parallel)
rangeStream.parallel();
long sum = rangeStream
.reduce(identity,
// Could also use (x, y) -> x + y
Math::addExact);
System.out.println((parallel ? "Parallel" : "Sequential")
+ " sum of first 100 numbers with identity "
+ identity
+ " = "
+ sum);
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args)
throws IOException {
Timer timer = new Timer();
List<String> primes =
iterate(2, i -> i + 1)
.parallel() // [1]
.filter(ParallelPrime::isPrime)
.limit(COUNT)
.mapToObj(Long::toString)
.collect(Collectors.toList());
System.out.println(timer.duration());
Files.write(Paths.get("primes.txt"), primes,
StandardOpenOption.CREATE);
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(CHECK);
long[] la = new long[SZ+1];
Arrays.parallelSetAll(la, i -> i);
Summing.timeTest("Array Stream Sum", CHECK, () ->
Arrays.stream(la).sum());
Summing.timeTest("Parallel", CHECK, () ->
Arrays.stream(la).parallel().sum());
Summing.timeTest("Basic Sum", CHECK, () ->
basicSum(la));
// Destructive summation:
Summing.timeTest("parallelPrefix", CHECK, () -> {
Arrays.parallelPrefix(la, Long::sum);
return la[la.length - 1];
});
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(CHECK);
timeTest("Sum Stream", CHECK, () ->
LongStream.rangeClosed(0, SZ).sum());
timeTest("Sum Stream Parallel", CHECK, () ->
LongStream.rangeClosed(0, SZ).parallel().sum());
timeTest("Sum Iterated", CHECK, () ->
LongStream.iterate(0, i -> i + 1)
.limit(SZ+1).sum());
// Slower & runs out of memory above 1_000_000:
// timeTest("Sum Iterated Parallel", CHECK, () ->
// LongStream.iterate(0, i -> i + 1)
// .parallel()
// .limit(SZ+1).sum());
}
}
代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra
@Test
void nextUidShouldGenerateUniqueValuesWhenParallelCalls() {
int nbEntries = 100;
long nbValues = LongStream.range(0, nbEntries)
.parallel()
.boxed()
.map(Throwing.function(x -> uidProvider.nextUid(null, mailbox)))
.distinct()
.count();
assertThat(nbValues).isEqualTo(nbEntries);
}
}
代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra
@Test
void nextModSeqShouldGenerateUniqueValuesWhenParallelCalls() {
int nbEntries = 100;
long nbValues = LongStream.range(0, nbEntries)
.parallel()
.map(Throwing.longUnaryOperator(x -> modSeqProvider.nextModSeq(null, mailbox)))
.distinct()
.count();
assertThat(nbValues).isEqualTo(nbEntries);
}
}
内容来源于网络,如有侵权,请联系作者删除!