이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 30. Streams
Streams were introduced in Java 8, allowing an efficient way of performing operations on very large data sets, including the entirety of a given cache. These operations are performed on collections instead of procedurally iterating over the entire dataset.
In addition, if the cache is distributed then operations may be performed even more efficiently as these may be performed across the cluster concurrently.
A
Stream
may be obtained by invoking the stream()
, for a single-threaded stream, or parallelStream()
, for a multi-threaded stream, methods on a given Map
. Parallel streams are discussed in more detail at Section 30.4.2, “Parallelism”.
30.1. Using Streams on a Local/Invalidation/Replication Cache 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
A stream used with a local, invalidation, or replication cache can be used identical to a stream on a regular collection.
For example, consider a cache that contains a number of Books. To create a Map that contains all entries with JBoss in the title the following could be used:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Map<Object, String> jbossBooks = cache.entrySet().stream() .filter(e -> e.getValue().getTitle().contains("JBoss")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<Object, String> jbossBooks = cache.entrySet().stream()
.filter(e -> e.getValue().getTitle().contains("JBoss"))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));