Switching the stream from parallel() to sequential() worked in the initial Stream API design, but caused many problems and finally the implementation was changed, so it just turns the parallel flag on and off for the whole pipeline. The current documentation is indeed vague, but it was improved in Java-9:
The stream pipeline is executed sequentially or in parallel depending on the mode of the stream on which the terminal operation is invoked. The sequential or parallel mode of a stream can be determined with the BaseStream.isParallel() method, and the stream's mode can be modified with the BaseStream.sequential() and BaseStream.parallel() operations. The most recent sequential or parallel mode setting applies to the execution of the entire stream pipeline.
def sample = ['Groovy', 'Gradle', 'Grails', 'Spock'] as String[]
def result = sample.stream() // Use stream() on array objects
.filter { s -> s.startsWith('Gr') }
.map { s -> s.toUpperCase() }
.toList() // toList() added to Stream by Groovy
Stream<String> a = Stream.of("one", "two");
Stream<String> b = Stream.of("three", "four");
Stream.concat(a, b);
or
Stream.of(a, b, c)
.reduce(Stream::concat)
.orElseGet(Stream::empty);
or
Stream.of(a, b, c).flatMap(s -> s);
// Convert elements to strings and concatenate them, separated by commas String joined = things.stream() .map(Object::toString) .collect(Collectors.joining(", "));
Learn Java 8 streams by example: functional programming with filter, map, flatMap, reduce, collect, lambdas, sequential and parallel streams are covered in-depth in this tutorial.
allows you to listen a live stream over Internet by using smartly resources. You can listen a webradio or share an event by allowing other listeners to make the same thing in the best conditions.
Yesterday, one of the JAXB users sent me an e-mail, asking for how to solve the problem he faced.
The scenario was like this; you have a client and a server, and you want a client to send an XML document to a server (through a good ol' TCP socket), then a server sends back an XML document. A very simple use case that should just work.
The problem he had is that unless the client sends the "EOS" (end of stream) signal to the server, the server keeps blocked. When he modified his code to send EOS by partial-closing the TCP socket (Socket.shutdownOutput), the server somehow won't be able to send back the response saying the socket is closed.
JSefa (Java Simple exchange format api) is a simple library for stream-based serialization of java objects to XML, CSV, and FLR (extensible to other formats) and back again using an iterator-style interface independent of the serialization format. The mapping between java object types and types of the serialization format (e. g. xml complex element types) can be defined either by annotating the java classes or programmatically using a simple API. The current implementation supports XML, CSV and FLR (Fixed Length Record) - for XML it is based on JSR 173.
JSR 173 (Stax) is a popular stream-based XML API for java providing an iterator-style interface ("pull"-mechanism in contrast to the "push"-mechanism provided by SAX). But JSR 173 defines a low-level API not designed for directly serializing java objects and back again. On the other hand traditional high-level APIs like JAXB or Castor are not stream-based, so that reading a xml document will generate java objects holding the data of the complete xml document in memory at the same time. Even the integration of StAX into JAXB 2.0 is only a first step to high-level streaming, as two independent APIs have to be used in parallel. JSefa provides a convenient and performant approach to high-level streaming using an iterator-style interface. It has a layered API with the top layer allowing the streaming to be independent of the serialization format type (XML, CSV or whatever). The current implementation provides support for XML, CSV, and FLR.
StreamCruncher is an Event Processor. It supports a language based on SQL which allows you to define "Event Processing" constructs like Sliding Windows, Time Based Windows, Partitions and Aggregates. Such constructs allow for the specification of boundaries (some are time sensitive) on a Stream of Events that SQL does not provide. Queries can be written using this language, which in turn can be used to monitor streams of incoming events. Multi-Stream Pattern Matching a.k.a Event Correlation is also possible. StreamCruncher is a multi-threaded Kernel that runs on Java™.
J. Auerbach, D. Bacon, P. Cheng, and R. Rabbah. OOPSLA '10: Proceedings of the ACM international conference on Object oriented programming systems languages and applications, page 89--108. New York, NY, USA, ACM, (2010)