forked from verhas/vtstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.adoc.jam
59 lines (36 loc) · 2.67 KB
/
README.adoc.jam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
= Virtual Thread Stream Library
The Virtual Thread Stream (VTS) library, contained within the `javax0.vtstream` package, leverages the power of virtual threads introduced in Java to provide a high-performance, easy-to-use streaming API that supports parallel processing with minimal overhead.
== Overview
*ThreadedStream* implements the Java `+Stream+` interface, providing a seamless integration with the existing stream API. This compatibility allows developers to easily adopt virtual thread-based parallelism in their applications, leveraging the rich set of stream operations such as `+map+`, `+filter+`, `+sorted+`, and more, without having to learn a new API.
== Features
- **Parallelism with Virtual Threads**: Utilize virtual threads for efficient parallel processing of stream operations, reducing the overhead associated with traditional multi-threading.
- **Flexible Stream Operations**: Supports a wide range of operations, including map, filter, distinct, limit, skip, and custom operations through the `Command` class.
- **Seamless Integration**: Easily integrates with existing Java codebases, allowing for the parallel processing of streams with minimal changes to the code.
== Usage
=== Creating a ThreadedStream
To create a `ThreadedStream`, you can use the static method `threaded` provided by the `ThreadedStream` class:
[source,java]
----
Stream<String> sourceStream = Stream.of("apple", "banana", "cherry");
ThreadedStream<String> threadedStream = ThreadedStream.threaded(sourceStream);
----
This creates a `ThreadedStream` that can process elements in parallel.
=== Applying Operations
Operations such as map, filter, and distinct are applied through the `Command` subclasses:
[source,java]
----
ThreadedStream<String> filteredStream = threadedStream.filter(s -> s.startsWith("a"));
ThreadedStream<String> mappedStream = filteredStream.map(String::toUpperCase);
----
Each operation returns a new `ThreadedStream` instance that represents the stream after the operation has been applied.
=== Terminal Operations
To execute the stream operations and collect results, you can use terminal operations like `forEach`, `collect`, or `reduce`:
[source,java]
----
List<String> result = mappedStream.collect(Collectors.toList());
----
This will execute the stream pipeline in parallel and collect the results into a list.
== Closing Thoughts
The Virtual Thread Stream library offers a powerful and flexible way to perform parallel stream processing in Java, making it easier to write efficient and scalable applications.
By leveraging virtual threads, it addresses many of the common challenges associated with parallelism, such as overhead and complexity.
Readme entirely generated by ChatGPT4.