SlideShare a Scribd company logo
JAVA 8 Parallel Stream
第五組:蔡詠捷、王登文、游憶文
outline
• Java 8 Lambda Expression
• Stream & Parallel Stream
• Code Demo
• Java Fork and Join using ForkJoinPool(Java7)
• Parallel Stream is good or not good?
• Conclusion
Java 8 Lambda Expression
Lambda Expression
• Java 8 support Lambda Expression then officially support functional
programming paradigm
• Lambda comes from the Lambda Calculus and refers to anonymous
functions in programming
• Lambda Expression
• Method argument 必須為一個 Functional Interface
• Functional Interface : Single Abstract Method interface(SAM interface)
• Ex : java.lang.Runnable, java.util.Comparator
Lambda Expression
• Functional Interface 定義:只有一個 public abstract method 的 Java
Interface
• 取代Functional Interface所產出的匿名類別,簡化程式碼
Lambda Expression
• @FunctionalInterface Annotation
Stream
• Stream 是一個Collection Wrapper,可以讓把集合內的元素 ( Elements ) 以
串流 ( Stream ) 形式交到 Stream Methods 以 Lambda Expression 執行
• Stream 執行時期如同 Iterator,單向而不可往返,資料只讀取一次,讀取過一
次後即用盡了
Stream
• Lazy evalutation
• JVM 在沒有遇到 terminal operations 前,並不會執行任何 Stream method
• Short-circuit execution
• JVM 會自行判斷 short-circuit,提早完成集合元素遍歷 ( Element traversal )
• Automatic parallelism
• JVM 可以把 Java Lambda Streams 同時交給多核心處理器 ( Multi-Core )或多線程
(Multi-Thread) 來執行,無須去編寫任何多線程代碼
Stream
• Lazy evaluation
• Code example
Stream
• Short circuit example
• ( fn1() || fn2() )
• if fn1() is true , fn2() will not execute
• ( fn1() && fn2() )
• if fn1() is false , fn2() will not execute
Stream
• Collection support
• Array support
Parallel Stream
• 直接將 Stream() 改為 ParallelStream()
• 要視硬體及JVM配置與JVM負載而定
• 也有可能造成負面作用(Side-effect)
Code Demo
Example Background
https://www.dropbox.com/s/dyx9rpxj53ofyxb/%E8%9E%A2%E5
%B9%95%E6%88%AA%E5%9C%96%202015-11-
01%2000.19.44.png?dl=0
Let’s look some examples~
In Java7, We do that......
https://www.dropbox.com/s/dyx9rpxj53ofyxb/%E8%9E%A2%E5
%B9%95%E6%88%AA%E5%9C%96%202015-11-
01%2000.19.44.png?dl=0
In Java8, We just need!
We can easily change to Parallel
Java Fork and Join using ForkJoinPool
Fork
• each subtask can be executed in parallel by different CPUs, or
different threads on the same CPU.
• The limit for when it makes sense to fork a task into subtasks is
also called a threshold. It is up to each task to decide on a sensible
threshold. It depends very much on the kind of work being done.
Join
Once the subtasks have finished
executing, the task may join (merge) all
the results into one result.
ForkJoinPool
A special thread pool which is designed to work well with
fork-and-join task splitting.
Example:As a parameter to the ForkJoinPool constructor
you pass the indicated level of parallelism you desire.
ForkJoinPool forkJoinPool = new ForkJoinPool(8);
As a parameter to the ForkJoinPool constructor you pass
the indicated level of parallelism you desire.
ForkJoinPool
You can submit two types of tasks. RecursiveAction and
RecursiveTask.
Action won’t return any result, just compute but task will return
something.
ForkJoinPool
You can submit two types of tasks. RecursiveAction and
RecursiveTask.
Action won’t return any result, just compute but task will return
something.
Use case:
MyRecursiveAction myRecursiveAction = new MyRecursiveAction(24);
forkJoinPool.invoke(myRecursiveAction);
Advanced Topic: http://coopsoft.com/ar/CalamityArticle.html
Parallel Stream is good or
not good?
Discuss Parallel Stream Good and Bad
Parallel Stream Problem
• Java 8 parallel streams may be
faster,not faster or slower
• streams 方法以低成本達到平行處
理(parallel processing)的方便性,
but they do almost in a ‘Black
Box’
• parallel processing != concurrent
processing. But most in Java 8
「automatic parallelization」
example like concurrent
processing.
Concurrent Processing VS Parallel Processing
Streams Good for
• They allow functional
programming style using
bindings.
• They allow for better
performance by removing
iteration. Iteration occurs with
evaluation. With streams, we can
bind dozens of functions without
iterating.
• Streams may be infinite.
Functions may be bound to
infinite streams without problem.
=>a short circuiting operation
Side Effect
• All streams use the same
ForkJoinPool=>very long
running task=> many long
running sub-tasks => use
each thread in pool
• one parallel subtask
performing I/O has side
effects on others
• Two Parallel Streams In One
ForjoinPool=>Occupied
Threads use
Use For Recommand
• Applicable
• Multi CPU
• Unrelation in I/O
• Split Pool & Num Setting
• Collection,Array…
• Not Applicable
• One CPU =>not good in performance
• In I/O Work
• Suggest:
• Don’t use in default ForkJoinPool(If WorkingTask and Server Setting
tolerate…)
Conclusion
• Parallel Stream seem to convenience and many benefits,but how many
question behind that is not known?
• Parallel streams is Unpredictable, and hard to be run in Correct
• All most of Parallel Stream Using can’t be predictable to know the
performance of the Normal and Unrelated process。
• Please ‘Parallel Stream’ easy to allay it…(Or if you have a high skill…)
Reference
• https://dzone.com/articles/think-twice-using-java-8
• http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/
• http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/
• https://wefollownews.appspot.com/cittopnews201408_48/14848.html
• http://openhome.cc/Gossip/Java/ParallelStream.html
• http://www.slideshare.net/dgomezg/parallel-streams-en-java-
8http://www.slideshare.net/JustinSDK/java-se-8-lambda
• http://magiclen.org/java-8-lambda/http://developer.51cto.com/art/201311/417451.htm
• Custom Thread Pool 參考 : http://stackoverflow.com/questions/21163108/custom-thread-
pool-in-java-8-parallel-stream
• ForkJoinPool submit, execute, invoke :
http://stackoverflow.com/questions/17881183/difference-between-execute-submit-and-
invoke-in-a-forkjoinpool

More Related Content

What's hot

Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
Mule java part-1
Mule java part-1Mule java part-1
Mule java part-1
Karnam Karthik
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
 
Java Batch
Java BatchJava Batch
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
Nawazish Mohammad Khan
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
Son Nguyen
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
Kresten Krab Thorup
 
Java 7: Fork/Join, Invokedynamic and the future
Java 7: Fork/Join, Invokedynamic and the futureJava 7: Fork/Join, Invokedynamic and the future
Java 7: Fork/Join, Invokedynamic and the future
Sander Mak (@Sander_Mak)
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
Rajat Pratap Singh
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
Martin Toshev
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
Ayush Sharma
 
Rjb
RjbRjb
Php 7 - YNS
Php 7 - YNSPhp 7 - YNS
Php 7 - YNS
Alex Amistad
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
Geertjan Wielenga
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012slandelle
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 

What's hot (19)

Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Mule java part-1
Mule java part-1Mule java part-1
Mule java part-1
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Java Batch
Java BatchJava Batch
Java Batch
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
 
Java 7: Fork/Join, Invokedynamic and the future
Java 7: Fork/Join, Invokedynamic and the futureJava 7: Fork/Join, Invokedynamic and the future
Java 7: Fork/Join, Invokedynamic and the future
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
Rjb
RjbRjb
Rjb
 
Php 7 - YNS
Php 7 - YNSPhp 7 - YNS
Php 7 - YNS
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
 

Viewers also liked

Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
David Gómez García
 
Don't just roll the dice ch2
Don't just roll the dice ch2Don't just roll the dice ch2
Don't just roll the dice ch2Brian Hu
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
IndicThreads
 
Java 8-streams-and-parallelism
Java 8-streams-and-parallelismJava 8-streams-and-parallelism
Java 8-streams-and-parallelism
Deepak Shevani
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
Heartin Jacob
 
Research presentation
Research presentationResearch presentation
Research presentation
Hailey Anderson
 
Conligus viet nam
Conligus viet namConligus viet nam
Conligus viet nam
teamhn
 
Format & Design
Format & DesignFormat & Design
Format & Design
drtaichi
 
JAPAN
JAPANJAPAN
JAPAN
bo_norah
 
Observing and Assessing Flow
Observing and Assessing FlowObserving and Assessing Flow
Observing and Assessing Flow
drtaichi
 
C politico
C politicoC politico
C politico
Piero Termini
 
Estudios a Medida
Estudios a MedidaEstudios a Medida
Estudios a Medida
Piero Termini
 
Arduino day 2015 @Archimedea
Arduino day 2015 @ArchimedeaArduino day 2015 @Archimedea
Arduino day 2015 @Archimedea
Archimedea s.r.l
 

Viewers also liked (17)

Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
Don't just roll the dice ch2
Don't just roll the dice ch2Don't just roll the dice ch2
Don't just roll the dice ch2
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Java 8-streams-and-parallelism
Java 8-streams-and-parallelismJava 8-streams-and-parallelism
Java 8-streams-and-parallelism
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
zhe_CRI2015_NHANES
zhe_CRI2015_NHANESzhe_CRI2015_NHANES
zhe_CRI2015_NHANES
 
Research presentation
Research presentationResearch presentation
Research presentation
 
Conligus viet nam
Conligus viet namConligus viet nam
Conligus viet nam
 
Format & Design
Format & DesignFormat & Design
Format & Design
 
VDOS2013-Zhe-Slides
VDOS2013-Zhe-SlidesVDOS2013-Zhe-Slides
VDOS2013-Zhe-Slides
 
JAPAN
JAPANJAPAN
JAPAN
 
Observing and Assessing Flow
Observing and Assessing FlowObserving and Assessing Flow
Observing and Assessing Flow
 
ZHE-BHI2012
ZHE-BHI2012ZHE-BHI2012
ZHE-BHI2012
 
C politico
C politicoC politico
C politico
 
Estudios a Medida
Estudios a MedidaEstudios a Medida
Estudios a Medida
 
Arduino day 2015 @Archimedea
Arduino day 2015 @ArchimedeaArduino day 2015 @Archimedea
Arduino day 2015 @Archimedea
 
Numan Noor
Numan NoorNuman Noor
Numan Noor
 

Similar to JAVA 8 Parallel Stream

Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
Oleg Tsal-Tsalko
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
Nicola Pedot
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
Gal Marder
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Java Closures
Java ClosuresJava Closures
Java Closures
Ben Evans
 
Java programming language
Java programming languageJava programming language
Java programming language
SubhashKumar329
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
Mindfire Solutions
 
Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Lauren Yew
 
reactive_programming_for_java_developers.pdf
reactive_programming_for_java_developers.pdfreactive_programming_for_java_developers.pdf
reactive_programming_for_java_developers.pdf
Akshitkumar437417
 
ForkJoinPools and parallel streams
ForkJoinPools and parallel streamsForkJoinPools and parallel streams
ForkJoinPools and parallel streams
Oresztész Margaritisz
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
CongTrung Vnit
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
Java 8
Java 8Java 8
Java introduction
Java introductionJava introduction
Java introduction
The icfai university jaipur
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
OOPC_Unit-I.pdf
OOPC_Unit-I.pdfOOPC_Unit-I.pdf
OOPC_Unit-I.pdf
KRaviChythanyaCSE
 
Kotlin REST & GraphQL API
Kotlin REST & GraphQL APIKotlin REST & GraphQL API
Kotlin REST & GraphQL API
Sean O'Brien
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick Guide
Anton Shchastnyi
 

Similar to JAVA 8 Parallel Stream (20)

Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Java programming language
Java programming languageJava programming language
Java programming language
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
 
reactive_programming_for_java_developers.pdf
reactive_programming_for_java_developers.pdfreactive_programming_for_java_developers.pdf
reactive_programming_for_java_developers.pdf
 
ForkJoinPools and parallel streams
ForkJoinPools and parallel streamsForkJoinPools and parallel streams
ForkJoinPools and parallel streams
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java 8
Java 8Java 8
Java 8
 
Java introduction
Java introductionJava introduction
Java introduction
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
OOPC_Unit-I.pdf
OOPC_Unit-I.pdfOOPC_Unit-I.pdf
OOPC_Unit-I.pdf
 
Kotlin REST & GraphQL API
Kotlin REST & GraphQL APIKotlin REST & GraphQL API
Kotlin REST & GraphQL API
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick Guide
 

JAVA 8 Parallel Stream

  • 1. JAVA 8 Parallel Stream 第五組:蔡詠捷、王登文、游憶文
  • 2. outline • Java 8 Lambda Expression • Stream & Parallel Stream • Code Demo • Java Fork and Join using ForkJoinPool(Java7) • Parallel Stream is good or not good? • Conclusion
  • 3. Java 8 Lambda Expression
  • 4.
  • 5. Lambda Expression • Java 8 support Lambda Expression then officially support functional programming paradigm • Lambda comes from the Lambda Calculus and refers to anonymous functions in programming • Lambda Expression • Method argument 必須為一個 Functional Interface • Functional Interface : Single Abstract Method interface(SAM interface) • Ex : java.lang.Runnable, java.util.Comparator
  • 6.
  • 7. Lambda Expression • Functional Interface 定義:只有一個 public abstract method 的 Java Interface • 取代Functional Interface所產出的匿名類別,簡化程式碼
  • 9. Stream • Stream 是一個Collection Wrapper,可以讓把集合內的元素 ( Elements ) 以 串流 ( Stream ) 形式交到 Stream Methods 以 Lambda Expression 執行 • Stream 執行時期如同 Iterator,單向而不可往返,資料只讀取一次,讀取過一 次後即用盡了
  • 10. Stream • Lazy evalutation • JVM 在沒有遇到 terminal operations 前,並不會執行任何 Stream method • Short-circuit execution • JVM 會自行判斷 short-circuit,提早完成集合元素遍歷 ( Element traversal ) • Automatic parallelism • JVM 可以把 Java Lambda Streams 同時交給多核心處理器 ( Multi-Core )或多線程 (Multi-Thread) 來執行,無須去編寫任何多線程代碼
  • 12. Stream • Short circuit example • ( fn1() || fn2() ) • if fn1() is true , fn2() will not execute • ( fn1() && fn2() ) • if fn1() is false , fn2() will not execute
  • 14. Parallel Stream • 直接將 Stream() 改為 ParallelStream() • 要視硬體及JVM配置與JVM負載而定 • 也有可能造成負面作用(Side-effect)
  • 17. Let’s look some examples~ In Java7, We do that...... https://www.dropbox.com/s/dyx9rpxj53ofyxb/%E8%9E%A2%E5 %B9%95%E6%88%AA%E5%9C%96%202015-11- 01%2000.19.44.png?dl=0
  • 18. In Java8, We just need!
  • 19. We can easily change to Parallel
  • 20. Java Fork and Join using ForkJoinPool
  • 21. Fork • each subtask can be executed in parallel by different CPUs, or different threads on the same CPU. • The limit for when it makes sense to fork a task into subtasks is also called a threshold. It is up to each task to decide on a sensible threshold. It depends very much on the kind of work being done.
  • 22. Join Once the subtasks have finished executing, the task may join (merge) all the results into one result.
  • 23. ForkJoinPool A special thread pool which is designed to work well with fork-and-join task splitting. Example:As a parameter to the ForkJoinPool constructor you pass the indicated level of parallelism you desire. ForkJoinPool forkJoinPool = new ForkJoinPool(8); As a parameter to the ForkJoinPool constructor you pass the indicated level of parallelism you desire.
  • 24. ForkJoinPool You can submit two types of tasks. RecursiveAction and RecursiveTask. Action won’t return any result, just compute but task will return something.
  • 25. ForkJoinPool You can submit two types of tasks. RecursiveAction and RecursiveTask. Action won’t return any result, just compute but task will return something.
  • 26. Use case: MyRecursiveAction myRecursiveAction = new MyRecursiveAction(24); forkJoinPool.invoke(myRecursiveAction); Advanced Topic: http://coopsoft.com/ar/CalamityArticle.html
  • 27. Parallel Stream is good or not good? Discuss Parallel Stream Good and Bad
  • 28. Parallel Stream Problem • Java 8 parallel streams may be faster,not faster or slower • streams 方法以低成本達到平行處 理(parallel processing)的方便性, but they do almost in a ‘Black Box’ • parallel processing != concurrent processing. But most in Java 8 「automatic parallelization」 example like concurrent processing.
  • 29. Concurrent Processing VS Parallel Processing
  • 30. Streams Good for • They allow functional programming style using bindings. • They allow for better performance by removing iteration. Iteration occurs with evaluation. With streams, we can bind dozens of functions without iterating. • Streams may be infinite. Functions may be bound to infinite streams without problem. =>a short circuiting operation
  • 31. Side Effect • All streams use the same ForkJoinPool=>very long running task=> many long running sub-tasks => use each thread in pool • one parallel subtask performing I/O has side effects on others • Two Parallel Streams In One ForjoinPool=>Occupied Threads use
  • 32. Use For Recommand • Applicable • Multi CPU • Unrelation in I/O • Split Pool & Num Setting • Collection,Array… • Not Applicable • One CPU =>not good in performance • In I/O Work • Suggest: • Don’t use in default ForkJoinPool(If WorkingTask and Server Setting tolerate…)
  • 33. Conclusion • Parallel Stream seem to convenience and many benefits,but how many question behind that is not known? • Parallel streams is Unpredictable, and hard to be run in Correct • All most of Parallel Stream Using can’t be predictable to know the performance of the Normal and Unrelated process。 • Please ‘Parallel Stream’ easy to allay it…(Or if you have a high skill…)
  • 34. Reference • https://dzone.com/articles/think-twice-using-java-8 • http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/ • http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ • https://wefollownews.appspot.com/cittopnews201408_48/14848.html • http://openhome.cc/Gossip/Java/ParallelStream.html • http://www.slideshare.net/dgomezg/parallel-streams-en-java- 8http://www.slideshare.net/JustinSDK/java-se-8-lambda • http://magiclen.org/java-8-lambda/http://developer.51cto.com/art/201311/417451.htm • Custom Thread Pool 參考 : http://stackoverflow.com/questions/21163108/custom-thread- pool-in-java-8-parallel-stream • ForkJoinPool submit, execute, invoke : http://stackoverflow.com/questions/17881183/difference-between-execute-submit-and- invoke-in-a-forkjoinpool