hanoi jug java 8 stream api

Click here to load reader

Post on 17-Jul-2015

1.213 views

Category:

Software

1 download

Embed Size (px)

TRANSCRIPT

Java 8: Stream API Vu Dang Ngoc - eXoHanoi JUG - 2015Introduction to Stream APIStream API at glanceAggregate Operations, Terminal OperationsLaziness and performance tuningHow Stream API change the way we coding?Advantage and disadvantageFurther readingHanoi JUG - 2015Stream example

Hanoi JUG - 2015Stream API at glance

Pipeline contain a data source, 1 or many intermediate operation, 1 terminal operation and linked together by streams. Hanoi JUG - 2015Stream source

Hanoi JUG - 2015Operations

Hanoi JUG - 2015Intermediate OperationStream-producing: require a stream and return another streamAlways lazyStateless and stateful operationsStateless (filter, map ): dont require information of other items.Stateful (distinct, sorted, limit, peek): require information of other items.Hanoi JUG - 2015Terminal Operation End of pipelinePush intermediate operator workingShort-circuiting: stream dont have to travel all data.Hanoi JUG - 2015Laziness and performance tuningIntermediate operator run only when Terminate operator asking

Hanoi JUG - 2015Laziness and performance tuning

Hanoi JUG - 2015Laziness and performance tuning

Hanoi JUG - 2015Stream is not loopcontinue to next element

You have no power here!Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How 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 - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015How Stream API change the way we coding?

Hanoi JUG - 2015make more clearly, reverting orderHow Stream API change the way we coding?

Hanoi JUG - 2015make more clearly, reverting orderParallel streamUsing Fork-Join PoolSide-effectSome parallel stream operations like reduce and collect need additional computationsAll sub-tasks should finish in a reasonable timeHanoi JUG - 2015Parallel stream

Hanoi JUG - 2015Parallel stream

Hanoi JUG - 2015Parallel stream

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Performance compare

Hanoi JUG - 2015Parallel stream performance is unstable

Hanoi JUG - 2015Advantage and DisadvantageThe GoodReduce size of codeEasy using parallel computingDeveloper can focus how to process dataBuilt-in feature of Collectors classThe BadNo customize operatorCannot random accessHanoi JUG - 2015Extend exampleAdvantage and DisadvantageAnd the UglyStream cannot reuseableParallel stream performance is unstable and unpredictableStream dont store data and cannot modify source collection.Can cause infinite streamHanoi JUG - 2015Infinite stream

Hanoi JUG - 2015Further readingCollection 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 streamActive vs Passive iteratorParallel Streams and SpliteratorsHanoi JUG - 2015more detailReferenthttp://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=2198914http://blog.credera.com/technology-insights/java/java-8-part-1-lamdas-streams-functional-interfaces/https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.htmlhttp://java.dzone.com/articles/think-twice-using-java-8http://blog.jooq.org/2014/06/13/java-8-friday-10-subtle-mistakes-when-using-the-streams-api/Hanoi JUG - 2015Questions & AnswersHanoi JUG - 2015