分析JDK中Stream的实现原理
2021-10-08 16:38:28 0 举报
登录查看完整内容
分析JDK中Stream的实现原理
作者其他创作
大纲/内容
unordered()、filter()、map()、mapToInt()、mapToLong()、mapToDouble()、flatMap()、flatMapToInt()、flatMapToDouble()、flatMapToLong()、peek()
accept
end
3
非短路(None Short-Circuiting)
4
sizeThreshold = 1
0101
Spliterator(X)
2
ORDERED.set
[2]
curChunk(SpinedNodeBuilder)
ForEachTask(Root Task)spliterator = source spliteratorparent = NULL
trySplit( )
execute Sink Chain in Fork 1 task thread
1
begin
index = 2
asArray( ) [copy to]
leftSplit
0
ChannelHandlerContext
create()
Spliterator(Root)
elements => [2]
forEach()、forEachOrdered()、toArray()、reduce()、collect()、max()、min()、count()
(2)
NULL
Spliterator(1-left)
next
fence = 2
execute Sink Chain in call thread
new fork task
state = new ArrayList<>( )
map op sink[ele * 2]
Spliterator(Y)
有状态(Stateful)
rightSplit
filter op sink[ele > 0]
sorted op sink[Comparator(Interger::compareTo)]
0000
SORTED.set
index = 0
fence = 3
ForEachTask(2-right-fork)spliterator = 2-rightparent = Root Task
state
无状态(Stateless)
forkRight = false
findFirst()、findAny()、anyMatch()、allMatch()、noneMatch()
Fork 2(by call thread)
fence = -1
prev
(1)
execute Sink Chain in fork task thread
短路(Short-Circuiting)
collect terminal sink[Collectors.toList()]
Channel
Stream操作分类
node builder terminal sink[toArray()]
SPLITERATOR_CHARACTERISTICS_MASK
[ ]
forEach terminal sink[System.out.println()]
Spliterator(X1)
println(2)
Spliterator(Y1)
DISTINCT.set
终结操作(Terminal Operations)
list = [2]
ForEachTask(1-left-fork)spliterator = 1-leftparent = Root Task
fence = 4
ChannelHandler
distinct()、sorted()、limit()、skip()、takeWhile()、dropWhile()
SHORT_CIRCUIT.clear
SIZED.set
forkRight = true
Object[16]
process in fork task
(3)
Spliterator(3-right)
ChannelPipeline
index = 3
中间操作(Intermediate Operations)
index = 1
fence = 1
IntFunction
Fork 1
Spliterator(3-left)
Spliterator(2-right)
31
Fork 3(by Fork 1 thread)
ForEachTask(3-left-fork)spliterator = 1-left(Root)parent = 1-left-fork
add(2)
next op sink
0 条评论
回复 删除
下一页