SlideShare a Scribd company logo
Hanoi JUG - 2015
Java 8: Stream API
Vu Dang Ngoc - eXo
Hanoi JUG - 2015
Introduction to Stream API
1. Stream API at glance
a. Aggregate Operations, Terminal Operations
b. Laziness and performance tuning
2. How Stream API change the way we coding?
3. Advantage and disadvantage
4. Further reading
Hanoi JUG - 2015
Stream example
Hanoi JUG - 2015
Stream API at glance
● Pipeline contain a data source, 1 or many intermediate
operation, 1 terminal operation and linked together by
streams.
Hanoi JUG - 2015
Stream source
Hanoi JUG - 2015
Operations
Hanoi JUG - 2015
Intermediate Operation
● Stream-producing: require a stream and
return another stream
● Always lazy
● Stateless and stateful operations
o Stateless (filter, map …): don’t require information of
other items.
o Stateful (distinct, sorted, limit, peek…): require
information of other items.
Hanoi JUG - 2015
Terminal Operation
● End of pipeline
● Push intermediate operator working
● Short-circuiting: stream don’t have to travel
all data.
Hanoi JUG - 2015
Laziness and performance tuning
● Intermediate operator run only when
Terminate operator asking
Hanoi JUG - 2015
Laziness and performance tuning
Hanoi JUG - 2015
Laziness and performance tuning
Hanoi JUG - 2015
Stream is not loop
continue to next
element
You have no power
here!
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
● Terminal operator collect provide many way
to transform data
● Collectors class provide built-in collection
feature.
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
How Stream API change the way we coding?
Hanoi JUG - 2015
Parallel stream
● Using Fork-Join Pool
● Side-effect
● Some parallel stream operations like reduce
and collect need additional computations
● All sub-tasks should finish in a reasonable
time
Hanoi JUG - 2015
Parallel stream
Hanoi JUG - 2015
Parallel stream
Hanoi JUG - 2015
Parallel stream
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Performance compare
Hanoi JUG - 2015
Parallel stream performance is unstable
Hanoi JUG - 2015
Advantage and Disadvantage
● The Good
o Reduce size of code
o Easy using parallel computing
o Developer can focus how to process data
o Built-in feature of Collectors class
● The Bad
o No customize operator
o Cannot random access
Hanoi JUG - 2015
Advantage and Disadvantage
● And the Ugly
o Stream cannot reuseable
o Parallel stream performance is unstable and
unpredictable
o Stream don’t store data and cannot modify source
collection.
o Can cause infinite stream
Hanoi JUG - 2015
Infinite stream
Hanoi JUG - 2015
Further reading
● Collection Pipes - article of Martin Fowler
about pipe and filter software pattern
● Java Fork-Join Calamity and Java Parallel
Calamity descript flaws of Fork/Join and
parallel stream
● Active vs Passive iterator
● Parallel Streams and Spliterators
Hanoi JUG - 2015
Referent
● http://www.java2novice.com/java-sorting-
algorithms/quick-sort/
● http://javapapers.com/java/java-stream-api/
● http://winterbe.com/posts/2014/07/31/java8-stream-
tutorial-examples/
● http://www.informit.com/articles/article.aspx?p=2198914
● http://blog.credera.com/technology-insights/java/java-8-
part-1-lamdas-streams-functional-interfaces/
● https://docs.oracle.com/javase/8/docs/api/java/util/strea
m/package-summary.html
● http://java.dzone.com/articles/think-twice-using-java-8
● http://blog.jooq.org/2014/06/13/java-8-friday-10-subtle-
mistakes-when-using-the-streams-api/
Hanoi JUG - 2015
Questions & Answers

More Related Content

Similar to Hanoi jug java 8 stream api

Hanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdasHanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdas
Benoît de CHATEAUVIEUX
 
Data Pipelines: Big Data Meets Salesforce
Data Pipelines: Big Data Meets SalesforceData Pipelines: Big Data Meets Salesforce
Data Pipelines: Big Data Meets Salesforce
Salesforce Developers
 
Gateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API GatewaysGateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API Gateways
Matt Turner
 
Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices Gateway
Robert Munteanu
 
Introduction to AngularJS - More Than Just Data Binding
Introduction to AngularJS - More Than Just Data BindingIntroduction to AngularJS - More Than Just Data Binding
Introduction to AngularJS - More Than Just Data Binding
Logical Advantage
 
API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017
Patrice Krakow
 
Data Pipelines -Big Data Meets Salesforce
Data Pipelines -Big Data Meets SalesforceData Pipelines -Big Data Meets Salesforce
Data Pipelines -Big Data Meets Salesforce
CarolEnLaNube
 
How to Build APIs - MHacks 2016
How to Build APIs - MHacks 2016How to Build APIs - MHacks 2016
How to Build APIs - MHacks 2016
Dan Cundiff
 
API Management for GraphQL
API Management for GraphQLAPI Management for GraphQL
API Management for GraphQL
WSO2
 
Magento Headless Commerce with Vue Storefront - Piyush Lathiya
Magento Headless Commerce with Vue Storefront - Piyush LathiyaMagento Headless Commerce with Vue Storefront - Piyush Lathiya
Magento Headless Commerce with Vue Storefront - Piyush Lathiya
Aureate Labs
 
Deccan ruby-conf-talk
Deccan ruby-conf-talkDeccan ruby-conf-talk
Deccan ruby-conf-talk
prchaudhari
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8
John Godoi
 
Restful api design
Restful api designRestful api design
Restful api design
Mizan Riqzia
 
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
South Tyrol Free Software Conference
 
Build your Business Services using ADF Task Flows
Build your Business Services using ADF Task FlowsBuild your Business Services using ADF Task Flows
Build your Business Services using ADF Task Flows
DataNext Solutions
 
How automate your SAP PI/PO/CPI and API management processes
How automate your SAP PI/PO/CPI and API management processesHow automate your SAP PI/PO/CPI and API management processes
How automate your SAP PI/PO/CPI and API management processes
Daniel Graversen
 
ADF Taskflows for beginners
ADF Taskflows for beginnersADF Taskflows for beginners
ADF Taskflows for beginners
Rajasekhar Manda
 
Exposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API ManagementExposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API Management
WSO2
 
Nurturing API Platforms with API Analytics
Nurturing API Platforms with API AnalyticsNurturing API Platforms with API Analytics
Nurturing API Platforms with API Analytics
WSO2
 
Api led connectivity_brazil
Api led connectivity_brazilApi led connectivity_brazil
Api led connectivity_brazil
Anupam Gogoi
 

Similar to Hanoi jug java 8 stream api (20)

Hanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdasHanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdas
 
Data Pipelines: Big Data Meets Salesforce
Data Pipelines: Big Data Meets SalesforceData Pipelines: Big Data Meets Salesforce
Data Pipelines: Big Data Meets Salesforce
 
Gateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API GatewaysGateway APIs, Envoy Gateway, and API Gateways
Gateway APIs, Envoy Gateway, and API Gateways
 
Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices Gateway
 
Introduction to AngularJS - More Than Just Data Binding
Introduction to AngularJS - More Than Just Data BindingIntroduction to AngularJS - More Than Just Data Binding
Introduction to AngularJS - More Than Just Data Binding
 
API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017
 
Data Pipelines -Big Data Meets Salesforce
Data Pipelines -Big Data Meets SalesforceData Pipelines -Big Data Meets Salesforce
Data Pipelines -Big Data Meets Salesforce
 
How to Build APIs - MHacks 2016
How to Build APIs - MHacks 2016How to Build APIs - MHacks 2016
How to Build APIs - MHacks 2016
 
API Management for GraphQL
API Management for GraphQLAPI Management for GraphQL
API Management for GraphQL
 
Magento Headless Commerce with Vue Storefront - Piyush Lathiya
Magento Headless Commerce with Vue Storefront - Piyush LathiyaMagento Headless Commerce with Vue Storefront - Piyush Lathiya
Magento Headless Commerce with Vue Storefront - Piyush Lathiya
 
Deccan ruby-conf-talk
Deccan ruby-conf-talkDeccan ruby-conf-talk
Deccan ruby-conf-talk
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8
 
Restful api design
Restful api designRestful api design
Restful api design
 
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
SFScon18 - Kurt Ranalter - Leonhard Holzer - API level regression testing: a ...
 
Build your Business Services using ADF Task Flows
Build your Business Services using ADF Task FlowsBuild your Business Services using ADF Task Flows
Build your Business Services using ADF Task Flows
 
How automate your SAP PI/PO/CPI and API management processes
How automate your SAP PI/PO/CPI and API management processesHow automate your SAP PI/PO/CPI and API management processes
How automate your SAP PI/PO/CPI and API management processes
 
ADF Taskflows for beginners
ADF Taskflows for beginnersADF Taskflows for beginners
ADF Taskflows for beginners
 
Exposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API ManagementExposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API Management
 
Nurturing API Platforms with API Analytics
Nurturing API Platforms with API AnalyticsNurturing API Platforms with API Analytics
Nurturing API Platforms with API Analytics
 
Api led connectivity_brazil
Api led connectivity_brazilApi led connectivity_brazil
Api led connectivity_brazil
 

Recently uploaded

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 

Recently uploaded (20)

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 

Hanoi jug java 8 stream api

  • 1. Hanoi JUG - 2015 Java 8: Stream API Vu Dang Ngoc - eXo
  • 2. Hanoi JUG - 2015 Introduction to Stream API 1. Stream API at glance a. Aggregate Operations, Terminal Operations b. Laziness and performance tuning 2. How Stream API change the way we coding? 3. Advantage and disadvantage 4. Further reading
  • 3. Hanoi JUG - 2015 Stream example
  • 4. Hanoi JUG - 2015 Stream API at glance ● Pipeline contain a data source, 1 or many intermediate operation, 1 terminal operation and linked together by streams.
  • 5. Hanoi JUG - 2015 Stream source
  • 6. Hanoi JUG - 2015 Operations
  • 7. Hanoi JUG - 2015 Intermediate Operation ● Stream-producing: require a stream and return another stream ● Always lazy ● Stateless and stateful operations o Stateless (filter, map …): don’t require information of other items. o Stateful (distinct, sorted, limit, peek…): require information of other items.
  • 8. Hanoi JUG - 2015 Terminal Operation ● End of pipeline ● Push intermediate operator working ● Short-circuiting: stream don’t have to travel all data.
  • 9. Hanoi JUG - 2015 Laziness and performance tuning ● Intermediate operator run only when Terminate operator asking
  • 10. Hanoi JUG - 2015 Laziness and performance tuning
  • 11. Hanoi JUG - 2015 Laziness and performance tuning
  • 12. Hanoi JUG - 2015 Stream is not loop continue to next element You have no power here!
  • 13. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 14. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 15. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 16. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 17. Hanoi JUG - 2015 How Stream API change the way we coding? ● Terminal operator collect provide many way to transform data ● Collectors class provide built-in collection feature.
  • 18. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 19. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 20. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 21. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 22. Hanoi JUG - 2015 How Stream API change the way we coding?
  • 23. Hanoi JUG - 2015 Parallel stream ● Using Fork-Join Pool ● Side-effect ● Some parallel stream operations like reduce and collect need additional computations ● All sub-tasks should finish in a reasonable time
  • 24. Hanoi JUG - 2015 Parallel stream
  • 25. Hanoi JUG - 2015 Parallel stream
  • 26. Hanoi JUG - 2015 Parallel stream
  • 27. Hanoi JUG - 2015 Performance compare
  • 28. Hanoi JUG - 2015 Performance compare
  • 29. Hanoi JUG - 2015 Performance compare
  • 30. Hanoi JUG - 2015 Performance compare
  • 31. Hanoi JUG - 2015 Performance compare
  • 32. Hanoi JUG - 2015 Performance compare
  • 33. Hanoi JUG - 2015 Performance compare
  • 34. Hanoi JUG - 2015 Performance compare
  • 35. Hanoi JUG - 2015 Performance compare
  • 36. Hanoi JUG - 2015 Performance compare
  • 37. Hanoi JUG - 2015 Performance compare
  • 38. Hanoi JUG - 2015 Parallel stream performance is unstable
  • 39. Hanoi JUG - 2015 Advantage and Disadvantage ● The Good o Reduce size of code o Easy using parallel computing o Developer can focus how to process data o Built-in feature of Collectors class ● The Bad o No customize operator o Cannot random access
  • 40. Hanoi JUG - 2015 Advantage and Disadvantage ● And the Ugly o Stream cannot reuseable o Parallel stream performance is unstable and unpredictable o Stream don’t store data and cannot modify source collection. o Can cause infinite stream
  • 41. Hanoi JUG - 2015 Infinite stream
  • 42. Hanoi JUG - 2015 Further reading ● Collection Pipes - article of Martin Fowler about pipe and filter software pattern ● Java Fork-Join Calamity and Java Parallel Calamity descript flaws of Fork/Join and parallel stream ● Active vs Passive iterator ● Parallel Streams and Spliterators
  • 43. Hanoi JUG - 2015 Referent ● http://www.java2novice.com/java-sorting- algorithms/quick-sort/ ● http://javapapers.com/java/java-stream-api/ ● http://winterbe.com/posts/2014/07/31/java8-stream- tutorial-examples/ ● http://www.informit.com/articles/article.aspx?p=2198914 ● http://blog.credera.com/technology-insights/java/java-8- part-1-lamdas-streams-functional-interfaces/ ● https://docs.oracle.com/javase/8/docs/api/java/util/strea m/package-summary.html ● http://java.dzone.com/articles/think-twice-using-java-8 ● http://blog.jooq.org/2014/06/13/java-8-friday-10-subtle- mistakes-when-using-the-streams-api/
  • 44. Hanoi JUG - 2015 Questions & Answers

Editor's Notes

  1. make more clearly, reverting order
  2. make more clearly, reverting order
  3. Extend example
  4. more detail