Multicore Programming
|
|
- Lee Berry
- 5 years ago
- Views:
Transcription
1 Multicore Programming Java Streams Louis-Claude Canon Bureau 414C Master 1 informatique Semestre 8 Louis-Claude Canon MCP Java Streams 1 / 124
2 Motivations Express simple iterations in a declarative way without writing the loop logic. Simple way to parallelize without writing the thread logic. Java Streams introduced in Java 8 (2014, LTS, support until 2025). Called iterators in Rust. Louis-Claude Canon MCP Java Streams 2 / 124
3 Outline Concepts Stream Operations Special Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 3 / 124
4 Concepts Stream Definition Outline Concepts Stream Definition Difference with Collections Intermediate and Terminal Operations Stream Operations Special Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 4 / 124
5 Concepts Stream Definition Example without Streams List<Dish> lowcal = new ArrayList<>(); for (Dish dish: menu) if (dish.getcalories() < 400) lowcaloricdishes.add(dish); Collections.sort(lowCal, new Comparator<Dish>() { public int compare(dish dish1, Dish dish2) { return Integer.compare(dish1.getCalories(), dish2.getcalories()); } }); List<String> lowcalname = new ArrayList<>(); for (Dish dish: lowcal) lowcalname.add(dish.getname()); Louis-Claude Canon MCP Java Streams 5 / 124
6 Concepts Stream Definition Example with Streams import static java.util.comparator.comparing; import static java.util.stream.collectors.tolist; List<String> lowcaloricdishesname = menu.stream().filter(d -> d.getcalories() < 400).sorted(comparing(Dish::getCalories)).map(Dish::getName).collect(toList()); Louis-Claude Canon MCP Java Streams 6 / 124
7
8
9 Concepts Stream Definition Benefits declarative (no flow control): readable and concise composable/flexible/extensible: easy to modify parallelizable Louis-Claude Canon MCP Java Streams 9 / 124
10 Concepts Stream Definition Definition A stream is a sequence of elements coming from a source and that supports data-processing operations. sequence of elements interface to access a sequenced set of values (not necessarily ordered) source data are provided by a collection, array or I/O resource data-processing operations support for database-like or functional operations Louis-Claude Canon MCP Java Streams 10 / 124
11 Concepts Stream Definition Characteristics Pipelining stream operation may return a stream Internal iteration iteration (loop logic) is implicit Louis-Claude Canon MCP Java Streams 11 / 124
12 Concepts Difference with Collections Outline Concepts Stream Definition Difference with Collections Intermediate and Terminal Operations Stream Operations Special Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 12 / 124
13 Concepts Difference with Collections Similarity between Streams and Collections Iteration on a sequenced set of values. Louis-Claude Canon MCP Java Streams 13 / 124
14 Concepts Difference with Collections Differences Lazy vs. Eager Evaluation: values are only computed as needed. Traversable only once: a stream cannot be consumed multiple times. Internal vs. external iterations: iterations can be transparently done in parallel or in a different more optimized order. Louis-Claude Canon MCP Java Streams 14 / 124
15 Concepts Intermediate and Terminal Operations Outline Concepts Stream Definition Difference with Collections Intermediate and Terminal Operations Stream Operations Special Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 15 / 124
16
17 Concepts Intermediate and Terminal Operations Intermediate Operations Intermediate operations: return another stream only define processing operations that will be performed (lazy evaluation) Louis-Claude Canon MCP Java Streams 17 / 124
18 Concepts Intermediate and Terminal Operations Example List<String> names = menu.stream().filter(dish -> { System.out.println("filter:" + dish.getname()); return dish.getcalories() > 300; }).map(dish -> { System.out.println("map:" + dish.getname()); return dish.getname(); }).limit(3).collect(tolist()); Louis-Claude Canon MCP Java Streams 18 / 124
19 Concepts Intermediate and Terminal Operations Example Output filtering:pork mapping:pork filtering:beef mapping:beef filtering:chicken mapping:chicken Louis-Claude Canon MCP Java Streams 19 / 124
20 Concepts Intermediate and Terminal Operations Terminal Operations Terminal operations produce a result from a stream pipeline (lazy evaluation). Louis-Claude Canon MCP Java Streams 20 / 124
21 Concepts Intermediate and Terminal Operations Summary A data source (such as a collection) to perform a query on. A chain of intermediate operations that form a stream pipeline. A terminal operation that executes the stream pipeline and produces a result. Louis-Claude Canon MCP Java Streams 21 / 124
22 Stream Operations Filtering Outline Concepts Stream Operations Filtering Slicing Mapping Finding and Matching Reducing Special Streams Collectors Parallel Data Processing Louis-Claude Canon MCP Java Streams 22 / 124
23 Stream Operations Filtering Predicate A predicate is a function returning a boolean. Used to filter values. Louis-Claude Canon MCP Java Streams 23 / 124
24 Stream Operations Filtering filter Louis-Claude Canon MCP Java Streams 24 / 124
25 Stream Operations Filtering distinct Louis-Claude Canon MCP Java Streams 25 / 124
26 Stream Operations Filtering Other Special Function Names From package java.util.function: Supplier void -> T Consumer T -> void Function T -> R UnaryOperator T -> T Predicate T -> boolean Equivalences with different arity: BiConsumer (T, U) -> void BiFunction (T, U) -> R BinaryOperator (T, T) -> T BiPredicate (T, U) -> boolean Louis-Claude Canon MCP Java Streams 26 / 124
27 Stream Operations Slicing Outline Concepts Stream Operations Filtering Slicing Mapping Finding and Matching Reducing Special Streams Collectors Parallel Data Processing Louis-Claude Canon MCP Java Streams 27 / 124
28 Stream Operations Slicing Definition Slicing: skip elements by ignoring either first or last elements. With a fixed number of elements: limit, skip. With a predicate (from Java 9): takewhile, dropwhile. Louis-Claude Canon MCP Java Streams 28 / 124
29 Stream Operations Slicing limit Louis-Claude Canon MCP Java Streams 29 / 124
30 Stream Operations Slicing skip Louis-Claude Canon MCP Java Streams 30 / 124
31 Stream Operations Slicing takewhile List<Dish> slicedmenu1 = specialmenu.stream().takewhile(dish -> dish.getcalories() < 320).collect(toList()); The methods takewhile and dropwhile are more efficient than a filter when you know that the source is sorted. Louis-Claude Canon MCP Java Streams 31 / 124
32 Stream Operations Mapping Outline Concepts Stream Operations Filtering Slicing Mapping Finding and Matching Reducing Special Streams Collectors Parallel Data Processing Louis-Claude Canon MCP Java Streams 32 / 124
33 Stream Operations Mapping map Applying a function: List<String> dishnames = menu.stream().map(dish::getname).collect(tolist()); Types: 1. menu: List<Dish> 2. menu.stream(): Stream<Dish> 3. menu.stream().map(): Stream<String> 4. menu.stream().map().collect(): List<String> Louis-Claude Canon MCP Java Streams 33 / 124
34 Stream Operations Mapping flatmap Flattening streams: List<String> uniquecharacters = words.stream().map(word -> word.split("")).flatmap(arrays::stream).distinct().collect(tolist()); Apply a function that returns a stream (as map). Merge the resulting streams into a single one. Louis-Claude Canon MCP Java Streams 34 / 124
35
36 Stream Operations Finding and Matching Outline Concepts Stream Operations Filtering Slicing Mapping Finding and Matching Reducing Special Streams Collectors Parallel Data Processing Louis-Claude Canon MCP Java Streams 36 / 124
37 Stream Operations Finding and Matching Matching: anymatch, allmatch, nonematch Rely on a predicate: boolean ishealthy = menu.stream().allmatch(dish -> dish.getcalories() < 1000); boolean ishealthy = menu.stream().nonematch(d -> d.getcalories() >= 1000); Louis-Claude Canon MCP Java Streams 37 / 124
38 Stream Operations Finding and Matching Short-Circuiting Interrupt the processing iteration on the stream as soon as a condition is met. Similar to evaluation mechanism with and &&. Apply to limit and takewhile as well. Allow infinite stream. Louis-Claude Canon MCP Java Streams 38 / 124
39 Stream Operations Finding and Matching Finding: findany, findfirst Optional<Dish> dish = menu.stream().filter(dish::isvegetarian).findany(); findany is better for parallelization than findfirst Louis-Claude Canon MCP Java Streams 39 / 124
40 Stream Operations Finding and Matching Optional<T> An object that is either defined or null (explicit management of null references). boolean ispresent() ifpresent(consumer<t> block) T get() T orelse(t other) Louis-Claude Canon MCP Java Streams 40 / 124
41 Stream Operations Reducing Outline Concepts Stream Operations Filtering Slicing Mapping Finding and Matching Reducing Special Streams Collectors Parallel Data Processing Louis-Claude Canon MCP Java Streams 41 / 124
42 Stream Operations Reducing reduce Reducing a list of elements into a single value (also called fold): int sum = numbers.stream().reduce(0, Integer::sum); Louis-Claude Canon MCP Java Streams 42 / 124
43
44 Stream Operations Reducing No Initial Value Optional<Integer> product = numbers.stream().reduce((a, b) -> (a * b)); Louis-Claude Canon MCP Java Streams 44 / 124
45 Stream Operations Reducing Maximum and Minimum Optional<Integer> max = numbers.stream().reduce( Integer::max); Optional<Integer> min = numbers.stream().reduce( Integer::min); Louis-Claude Canon MCP Java Streams 45 / 124
46 Stream Operations Reducing Stateless vs. Stateful reduce is stateful (with a bounded state), i.e. it keeps an intermediate result (called an accumulator). sorted and distinct are even more stateful (unbounded state): they need to buffer all the elements of the stream to proceed. Louis-Claude Canon MCP Java Streams 46 / 124
47 Stream Operations Reducing Summary In addition to the distinction between intermediate and terminal operations, operations are characterized by whether they: allow short-circuiting (takewhile, limit, find, match) return an optional (for terminal operations): find, reduce, min, max are stateful (bounded or not): limit, skip, takewhile, dropwhile, distinct (un), sorted (un), (reduce) Louis-Claude Canon MCP Java Streams 47 / 124
48 Special Streams Numeric Streams Outline Concepts Stream Operations Special Streams Numeric Streams Building Streams Infinite Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 48 / 124
49 Special Streams Numeric Streams Primitive Stream Specializations IntStream, DoubleStream and LongStream. Avoid unboxing and boxing (more efficient data representation). Additional methods for efficiency and convenience: min, max, sum, average, etc. Louis-Claude Canon MCP Java Streams 49 / 124
50 Special Streams Numeric Streams To and From a Primitive Stream maptoint: boxed: int calories = menu.stream().maptoint(dish::getcalories).sum(); Stream<Integer> stream = intstream.boxed(); Louis-Claude Canon MCP Java Streams 50 / 124
51 Special Streams Numeric Streams Specialized Optionals OptionalInt OptionalDouble OptionalLong Louis-Claude Canon MCP Java Streams 51 / 124
52 Special Streams Building Streams Outline Concepts Stream Operations Special Streams Numeric Streams Building Streams Infinite Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 52 / 124
53 Special Streams Building Streams From Values Stream<String> stream = Stream.of("Modern ", "Java ", "In ", "Action"); Louis-Claude Canon MCP Java Streams 53 / 124
54 Special Streams Building Streams From Nullable From Java 9: String homevalue = System.getProperty("home"); Stream<String> homevaluestream = homevalue == null? Stream.empty() : Stream.of(value); Stream<String> homevaluestream = Stream.ofNullable(System.getProperty("home")); A stream with a null value differs from an empty stream. Louis-Claude Canon MCP Java Streams 54 / 124
55 Special Streams Building Streams From Arrays int[] numbers = {2, 3, 5, 7, 11, 13}; int sum = Arrays.stream(numbers).sum(); Louis-Claude Canon MCP Java Streams 55 / 124
56 Special Streams Building Streams From a Collection List<Integer> numbers = Arrays.asList(1, 2, 1, 3, 3, 2, 4); int sum = numbers.stream().sum(); Louis-Claude Canon MCP Java Streams 56 / 124
57 Special Streams Building Streams From Files long uniquewords = 0; try (Stream<String> lines = Files.lines(Paths.get("data.txt"), Charset.defaultCharset())) { uniquewords = lines.flatmap(line -> Arrays.stream(line.split(" "))).distinct().count(); } catch (IOException e) { } Louis-Claude Canon MCP Java Streams 57 / 124
58 Special Streams Building Streams From Numeric Ranges IntStream evennumbers = IntStream.rangeClosed(1, 100).filter(n -> n % 2 == 0); range is exclusive rangeclosed is inclusive Louis-Claude Canon MCP Java Streams 58 / 124
59 Special Streams Infinite Streams Outline Concepts Stream Operations Special Streams Numeric Streams Building Streams Infinite Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 59 / 124
60 Special Streams Infinite Streams iterate Stream.iterate(0, n -> n + 2).limit(10).forEach(System.out::println); IntStream.iterate(0, n -> n < 100, n -> n + 4).forEach(System.out::println); Needs a short-circuiting operation to terminate. No unbounded stateful operation (reduce and sorted). Louis-Claude Canon MCP Java Streams 60 / 124
61 Special Streams Infinite Streams generate Stream.generate(Math::random).limit(5).forEach(System.out::println); Requires a stateful (with a mutable state) supplier. Louis-Claude Canon MCP Java Streams 61 / 124
62 Collectors collect Summary and References Louis-Claude Canon MCP Java Streams 62 / 124 Outline Concepts Stream Operations Special Streams Collectors collect Reducing and Summarizing Grouping and Partitioning Custom Collector Parallel Data Processing
63 Collectors collect collect Collect the final result as the terminal operation. Require a Collector object as its parameter. A collector is designed to work on a stream. No relation with Collection. Several ways to define such collectors in class Collectors. stream.collect(tolist()); Louis-Claude Canon MCP Java Streams 63 / 124
64 Collectors Reducing and Summarizing Summary and References Louis-Claude Canon MCP Java Streams 64 / 124 Outline Concepts Stream Operations Special Streams Collectors collect Reducing and Summarizing Grouping and Partitioning Custom Collector Parallel Data Processing
65 Collectors Reducing and Summarizing maxby and minby Comparator<Dish> dishcaloriescomparator = Comparator.comparingInt(Dish::getCalories); Optional<Dish> mostcaloriedish = menu.stream().collect(maxby(dishcaloriescomparator)); Louis-Claude Canon MCP Java Streams 65 / 124
66 Collectors Reducing and Summarizing Summarizing: summinint, counting, averagingint and summarizingint int totalcalories = menu.stream().collect(summingint(dish::getcalories)); long count = menu.stream().collect(counting()); double avgcalories = menu.stream().collect(averagingint(dish::getcalories)); IntSummaryStatistics menustatistics = menu.stream().collect(summarizingint(dish::getcalories)); Louis-Claude Canon MCP Java Streams 66 / 124
67
68 Collectors Reducing and Summarizing joining String shortmenu = menu.stream().map(dish::getname).collect(joining(", ")); Louis-Claude Canon MCP Java Streams 68 / 124
69 Collectors Reducing and Summarizing reducing int totalcalories = menu.stream().collect(reducing(0, Dish::getCalories, Integer::sum)); Generalization of previous summarizing operations. First apply map function (e.g. getcalories), and then performs the reduction operation (e.g. sum). Louis-Claude Canon MCP Java Streams 69 / 124
70
71 Collectors Reducing and Summarizing reduce, reducing and collect reducing is like reduce but for a multi-level reduction. reduce must work on an immutable state (the accumulating and combining functions should have no side effect) because it can be parallelized. collect builds incrementally a mutable object (more efficient for strings because of StringBuilder). Louis-Claude Canon MCP Java Streams 71 / 124
72 Collectors Grouping and Partitioning Summary and References Louis-Claude Canon MCP Java Streams 72 / 124 Outline Concepts Stream Operations Special Streams Collectors collect Reducing and Summarizing Grouping and Partitioning Custom Collector Parallel Data Processing
73 Collectors Grouping and Partitioning Example without Streams Map<Currency, List<Transaction>> transbycurr = new HashMap<>(); for (Transaction transaction : transactions) { Currency currency = transaction.getcurrency(); List<Transaction> transactionsforcurrency = transbycurr.get(currency); if (transactionsforcurrency == null) { transactionsforcurrency = new ArrayList<>(); transbycurr.put(currency, transactionsforcurrency); } transactionsforcurrency.add(transaction); } Louis-Claude Canon MCP Java Streams 73 / 124
74 Collectors Grouping and Partitioning groupingby Map<Currency, List<Transaction>> transbycurr = transactions.stream().collect(groupingby(transaction::getcurrency)); Louis-Claude Canon MCP Java Streams 74 / 124
75
76 Collectors Grouping and Partitioning Second Example Map<Dish.Type, List<Dish>> dishesbytype = menu.stream().collect(groupingby(dish::gettype)); Louis-Claude Canon MCP Java Streams 76 / 124
77
78 Collectors Grouping and Partitioning Grouping without Classification Function public enum CaloricLevel { DIET, NORMAL, FAT } Map<CaloricLevel, List<Dish>> dishesbycaloriclevel = menu.stream().collect(groupingby(dish -> { if (dish.getcalories() <= 400) return CaloricLevel.DIET; else if (dish.getcalories() <= 700) return CaloricLevel.NORMAL; else return CaloricLevel.FAT; } )); Louis-Claude Canon MCP Java Streams 78 / 124
79 Collectors Grouping and Partitioning filtering Result: Map<Dish.Type, List<Dish>> caloricdishesbytype = menu.stream().collect(groupingby(dish::gettype, filtering(dish -> dish.getcalories() > 500, tolist()))); {OTHER=[french fries, pizza], MEAT=[pork, beef], FISH=[]} Louis-Claude Canon MCP Java Streams 79 / 124
80 Collectors Grouping and Partitioning mapping Map<Dish.Type, List<String>> dishnamesbytype = menu.stream().collect(groupingby(dish::gettype, mapping(dish::getname, tolist()))); flatmapping when generating a stream for each object instead of an object only (merge the streams). Louis-Claude Canon MCP Java Streams 80 / 124
81 Collectors Grouping and Partitioning Multilevel Grouping Map<Dish.Type, Map<CaloricLevel, List<Dish>>> res = menu.stream().collect( groupingby(dish::gettype, groupingby(dish -> { if (dish.getcalories() <= 400) return CaloricLevel.DIET; else if (dish.getcalories() <= 700) return CaloricLevel.NORMAL; else return CaloricLevel.FAT; } ) ) ); Louis-Claude Canon MCP Java Streams 81 / 124
82
83 Collectors Grouping and Partitioning collectingandthen To apply a specific function on the result of the collection operation: Map<Dish.Type, Dish> mostcaloricbytype = menu.stream().collect(groupingby(dish::gettype, collectingandthen( maxby(comparingint(dish::getcalories)), Optional::get))); Louis-Claude Canon MCP Java Streams 83 / 124
84
85 Collectors Grouping and Partitioning partitioningby Map<Boolean, List<Dish>> partitionedmenu = menu.stream().collect(partitioningby(dish::isvegetarian)); Always generate lists for both true and false. Special map optimized for two values. Louis-Claude Canon MCP Java Streams 85 / 124
86 Collectors Custom Collector Summary and References Louis-Claude Canon MCP Java Streams 86 / 124 Outline Concepts Stream Operations Special Streams Collectors collect Reducing and Summarizing Grouping and Partitioning Custom Collector Parallel Data Processing
87 Collectors Custom Collector Collector Interface public interface Collector<T, A, R> { Supplier<A> supplier(); BiConsumer<A, T> accumulator(); Function<A, R> finisher(); BinaryOperator<A> combiner(); Set<Characteristics> characteristics(); } T stream element A accumulator element (temporary/intermediate result) R final returned element Example: tolist Louis-Claude Canon MCP Java Streams 87 / 124
88 Collectors Custom Collector Supplier Initial value for the accumulator: public Supplier<List<T>> supplier() { return ArrayList::new; } Louis-Claude Canon MCP Java Streams 88 / 124
89 Collectors Custom Collector Accumulator Takes an element and merge it with the accumulator: public BiConsumer<List<T>, T> accumulator() { return List::add; } Louis-Claude Canon MCP Java Streams 89 / 124
90 Collectors Custom Collector Finisher Convert the accumulator to the final result: public Function<List<T>, List<T>> finisher() { return Function.identity(); } Louis-Claude Canon MCP Java Streams 90 / 124
91
92 Collectors Custom Collector Combiner Combine two accumulators: public BinaryOperator<List<T>> combiner() { return (list1, list2) -> { list1.addall(list2); return list1; } } Allows the parallelization: each core processes a part of the stream, which leads to a set of accumulators that are combined. Louis-Claude Canon MCP Java Streams 92 / 124
93
94 Collectors Custom Collector Characteristics UNORDERED stream order is not important CONCURRENT can be parallelized (on all streams if UNORDERED, on unordered streams only otherwise) IDENTITY_FINISH finisher is the identity function public Set<Characteristics> characteristics() { return Collections.unmodifiableSet(EnumSet.of( IDENTITY_FINISH, CONCURRENT)); } Louis-Claude Canon MCP Java Streams 94 / 124
95 Collectors Custom Collector Alternative List<Dish> dishes = menustream.collect(arraylist::new, List::add, List::addAll); Louis-Claude Canon MCP Java Streams 95 / 124
96 Parallel Data Processing Parallel Streams Outline Concepts Stream Operations Special Streams Collectors Parallel Data Processing Parallel Streams Fork/join Framework Spliterator Summary and References Louis-Claude Canon MCP Java Streams 96 / 124
97 Parallel Data Processing Parallel Streams Thread Logic Parallelizing a processing code requires to: 1. split the data structure into chunks; 2. assign each chunk to a different thread; 3. synchronize the executions and combine the results. Parallel streams hide this logic but each step can be customized. Louis-Claude Canon MCP Java Streams 97 / 124
98 Parallel Data Processing Parallel Streams parallel and sequential A stream is either: sequential (by default or with the method sequential) or parallel (with the method parallel). The last call in the stream construction wins. LongStream.rangeClosed(1, N).parallel().sum(); Louis-Claude Canon MCP Java Streams 98 / 124
99
100 Parallel Data Processing Parallel Streams Settings the Number of Threads In the common pool, there is by default one less threads as there are processors (to let room for the main thread). With the command line: java -Djava.util.concurrent.ForkJoinPool.common. parallelism=3 In the code: System.setProperty( "java.util.concurrent.forkjoinpool.common. parallelism", "3"); ForkJoinPool forkjoinpool = new ForkJoinPool(3); forkjoinpool.submit( () -> stream.terminalop() ).get(); Louis-Claude Canon MCP Java Streams 100 / 124
101 Parallel Data Processing Parallel Streams Pitfalls Necessary to understand the semantics to predict how the stream will be parallelized. Performance issue: Stream.iterate(1L, i -> i + 1).limit(n).parallel().reduce(0L, Long::sum); Correctness issue: Accumulator accumulator = new Accumulator(); LongStream.rangeClosed(1, n).foreach(accumulator::add); Louis-Claude Canon MCP Java Streams 101 / 124
102 Parallel Data Processing Parallel Streams Measuring Performance Critical to test performance (even if code is well understood). Speed-up: ratio of sequential execution time over parallel execution time. With n cores, the ideal speed-up is n. Micro-benchmarking is difficult: Cold-start (warm-up). Variability (multiple iterations) Java Microbenchmark Harness (JMH). Louis-Claude Canon MCP Java Streams 102 / 124
103 Parallel Data Processing Parallel Streams General Advices Avoid boxing (prefer primitive stream specialization). limit, findfirst rely on the order and require synchronization. findany and unordered may solve this issue. Avoid parallelizing small streams with few data or processing. Prefer underlying data source that can be split efficiently (e.g. ArrayList, rangeclosed, and streams that convey their sizes). Be cautious of costly combiner method. Measure and test. Louis-Claude Canon MCP Java Streams 103 / 124
104 Parallel Data Processing Fork/join Framework Outline Concepts Stream Operations Special Streams Collectors Parallel Data Processing Parallel Streams Fork/join Framework Spliterator Summary and References Louis-Claude Canon MCP Java Streams 104 / 124
105 Parallel Data Processing Fork/join Framework ForkJoinPool Parallel streams rely on the class ForkJoinPool, which is an implementation of ExecutorService. Split tasks and distribute them on a pool of threads. Louis-Claude Canon MCP Java Streams 105 / 124
106
107 Parallel Data Processing Fork/join Framework Work-Stealing Creation of more tasks than available threads because tasks may be heterogeneous. Each thread starts by splitting tasks, putting them in their execution queue. Once a task is small enough, it is executed. When a thread finishes all tasks in its execution queue, it steals waiting tasks from the other queues. Louis-Claude Canon MCP Java Streams 107 / 124
108
109 Parallel Data Processing Spliterator Outline Concepts Stream Operations Special Streams Collectors Parallel Data Processing Parallel Streams Fork/join Framework Spliterator Summary and References Louis-Claude Canon MCP Java Streams 109 / 124
110 Parallel Data Processing Spliterator Interface Splitable iterator: define how to split the stream that is iterated. public interface Spliterator<T> { boolean tryadvance(consumer<? super T> action); Spliterator<T> trysplit(); long estimatesize(); int characteristics(); } Louis-Claude Canon MCP Java Streams 110 / 124
111 Parallel Data Processing Spliterator trysplit Logic for splitting data stream. public Spliterator trysplit() { if (currentsize < MIN_SIZE) return null; long half = currentsize / 2; currentsize -= half; return new Spliterator(half); } Louis-Claude Canon MCP Java Streams 111 / 124
112
113 Parallel Data Processing Spliterator tryadvance Feeds the consumer with the next stream element. public boolean tryadvance(consumer action) { action.accept(nextvalue()); currentsize--; return currentsize!= 0; } Louis-Claude Canon MCP Java Streams 113 / 124
114 Parallel Data Processing Spliterator estimatesize The size can be estimated (used for balancing work). public long estimatesize() { return currentsize; } Louis-Claude Canon MCP Java Streams 114 / 124
115 Parallel Data Processing Spliterator characteristics Information to control or optimize the usage of the spliterator. public int characteristics() { return ORDERED + DISTINCT + SORTED + CONCURRENT + SIZED + SUBSIZED + NONNULL + IMMUTABLE; } ORDERED the order of the elements must be enforced DISTINCT all elements are distinct SORTED elements are sorted CONCURRENT the modification of the stream source is thread-safe SIZE the estimated size is precise SUBSIZED all created spliterators are SIZED NON-NULL all elements are non-null IMMUTABLE the stream source cannot be modified Louis-Claude Canon MCP Java Streams 115 / 124
116 Summary and References Outline Concepts Stream Operations Special Streams Collectors Parallel Data Processing Summary and References Louis-Claude Canon MCP Java Streams 116 / 124
117 Summary and References Stream Concepts A stream is a sequence of elements from a source that supports data-processing operations. Streams make use of internal iteration: the iteration is abstracted away through operations such as filter, map, and sorted. There are two types of stream operations: intermediate and terminal operations. Intermediate operations such as filter and map return a stream and can be chained together. They are used to set up a pipeline of operations but do not produce any result. Terminal operations such as foreach and count return a non-stream value and process a stream pipeline to return a result. The elements of a stream are computed on demand ( lazily ). Louis-Claude Canon MCP Java Streams 117 / 124
118 Summary and References Stream Operations The Streams API lets you express complex data processing queries. You can filter and slice a stream using the filter, distinct, takewhile (Java 9), dropwhile (Java 9), skip, and limit methods. You can extract or transform elements of a stream with map and flatmap. You can find elements in a stream using findfirst and findany. You can match a given predicate in a stream using the allmatch, nonematch, and anymatch methods. These methods make use of short-circuiting: a computation stops as soon as a result is found; there is no need to process the whole stream. You can combine all elements of a stream iteratively to produce a result using the reduce method, for example, to calculate the sum or find the maximum of a stream. Some operations such as filter and map are stateless: they do not store any state. Some operations such as reduce store state to calculate a value: they are stateful. Louis-Claude Canon MCP Java Streams 118 / 124
119 Summary and References Special Streams There are three primitive specializations of streams: IntStream, DoubleStream, and LongStream. Their operations are also specialized accordingly. Streams can be created not only from a collection but also from values, arrays, files, and specific methods such as iterate and generate. An infinite stream has an infinite number of elements (for example all possible strings). This is possible because the elements of a stream are only produced on demand. You can get a finite stream from an infinite stream using methods such as limit. Louis-Claude Canon MCP Java Streams 119 / 124
120 Summary and References Collectors collect is a terminal operation that takes as argument various recipes (called collectors) for accumulating the elements of a stream into a summary result. Predefined collectors include reducing and summarizing stream elements into a single value, such as calculating the minimum, maximum, or average. Predefined collectors let you group elements of a stream with groupingby and partition elements of a stream with partitioningby. Collectors compose effectively to create multilevel groupings, partitions, and reductions. You can develop your own collectors by implementing the methods defined in the Collector interface. Louis-Claude Canon MCP Java Streams 120 / 124
121 Summary and References Parallel Data Processing Internal iteration allows you to process a stream in parallel without the need to explicitly use and coordinate different threads in your code. Behavior and performance of parallel code can be counterintuitive, it is always necessary to check and measure them. Parallel execution can improve performance, especially when the number of elements is large or the processing is time consuming. From a performance point of view, using the right data structure (e.g. primitive streams) is more important than trying parallelization. The fork/join framework is used to recursively split streams and distribute them with a work-stealing approach. Spliterator s define how a parallel stream can split the data it traverses. Louis-Claude Canon MCP Java Streams 121 / 124
122 Summary and References Official Documentation Documentation of package stream Documentation of interface Stream Documentation of interface Collector Documentation of class Collectors Documentation of interface Spliterator Louis-Claude Canon MCP Java Streams 122 / 124
123 Summary and References Modern Java in Action, 2nd edition, 2018 Covers recent Java additions (Java 8, 9 and 10). Presents streams, API improvements, lambdas, reactive programming and functional-style Java programming. Louis-Claude Canon MCP Java Streams 123 / 124
124 Summary and References Demonstration Compute the sum of all square numbers between 1 and n. IntStream.rangeClosed(1, n).filter(i -> { var x = Math.floor(Math.sqrt(i)); return x * x == i; }).sum() Louis-Claude Canon MCP Java Streams 124 / 124
Collectors. Raoul-Gabriel Urma Richard Warburton James Gough
Collectors Raoul-Gabriel Urma Richard Warburton James Gough Outline of module 1. Grouping and partitioning 2. Collection operations 3. Arithmetic and reducing collectors 4. Advanced queries Grouping and
More informationJava8: Stream Style. Sergey
Java8: Stream Style Sergey Kuksenko sergey.kuksenko@oracle.com, @kuksenk0 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be
More informationJava Technologies. Lecture V. Valdas Rapševičius
Preparation of the material was supported by the project Increasing Internationality in Study Programs of the Department of Computer Science II, project number VP1 2.2 ŠMM-07-K-02-070, funded by The European
More informationStreams in Java 8. Start programming in a more functional style
Streams in Java 8 Start programming in a more functional style Background Who am I? Tobias Coetzee I m a Technical Lead at BBD I present the Java Expert Level Certifications at BBD (EJB, JPA, etc.) I m
More informationAdvanced Programming Methods. Lecture 4 - Functional Programming in Java
Advanced Programming Methods Lecture 4 - Functional Programming in Java Important Announcement: At Seminar 6 (7-13 November 2017) you will have a closed-book test (based on your laboratory work). Overview
More informationLambdas, streams, and functional-style programming IN ACTION. Raoul-Gabriel Urma Mario Fusco Alan Mycroft S AMPLE CHAPTER MANNING
Lambdas, streams, and functional-style programming IN ACTION Raoul-Gabriel Urma Mario Fusco Alan Mycroft S AMPLE CHAPTER MANNING Java 8 in Action by Raoul-Gabriel Urma Mario Fusco Alan Mycroft Chapter
More informationLAMBDA EXPRESSIONS AND STREAMS API
Java 8 LAMBDA EXPRESSIONS AND STREAMS API An Introduction Methods As Data 2 @FunctionalInterface public interface Runnable { public abstract void run(); public interface ActionListener extends EventListener
More informationPerchance to Stream with Java 8
Perchance to Stream with Java 8 Paul Sandoz Oracle The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated $$ into
More informationFunctional Constructs in Java 8: Lambdas and Streams
Functional Constructs in Java 8: Lambdas and Streams Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 6 due Thursday 11:59 pm Final exam Tuesday, May 3, 5:30-8:30 pm, PH 100
More informationLambdas & Streams In JDK 8: Beyond The Basics
Lambdas & Streams In JDK 8: Beyond The Basics Simon Ritter Deputy CTO, Azul Systems @speakjava azul.com Copyright Azul Systems 2015 1 A clever man learns from his mistakes......a wise man learns from other
More informationJava 8 Parallel Stream Internals (Part 2)
Java 8 Parallel Stream Internals (Part 2) Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt
More information301AA - Advanced Programming
301AA - Advanced Programming Lecturer: Andrea Corradini andrea@di.unipi.it h;p://pages.di.unipi.it/corradini/ Course pages: h;p://pages.di.unipi.it/corradini/dida@ca/ap-18/ AP-2018-23: Streams in Java
More informationJava SE 8: Lambda Expressions And The Stream API
Java SE 8: Lambda Expressions And The Stream API Simon Ritter Head of Java Technology Evangelism Java Product Management Java Day Tokyo 2015 April 8, 2015 Safe Harbor Statement The following is intended
More informationJava 8 new features Juan Hernández
Java 8 new features Juan Hernández Dec 1st 2015 1 / 73 Introduction In this session we will do an introduction to the new features introduced by Java 8 for functional programming: λ-expressions and the
More informationJava SE 8 Programming
Java SE 8 Programming Training Calendar Date Training Time Location 16 September 2019 5 Days Bilginç IT Academy 28 October 2019 5 Days Bilginç IT Academy Training Details Training Time : 5 Days Capacity
More informationJava SE 8 Programming
Oracle University Contact Us: +52 1 55 8525 3225 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming
More informationAdvanced Java Programming
Advanced Java Programming Programming Technologies 2015/2016 spring Kollár, Lajos Kocsis, Gergely (English version) Advanced Java Programming Java 5 Generics (Enums) Java 7 Strings in switch try-with-resources
More informationJava SE 8 Programming
Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features
More informationCommon mistakes made with Functional Java. Brian Vermeer
Common mistakes made with Functional Java Brian Vermeer (@BrianVerm) Brian Vermeer Software Engineer Doing too much in a single lambda @BrianVerm Lambda Expression In computer programming, a lambda
More informationFunctional Programming in Java Part 2. CSE 219 Department of Computer Science, Stony Brook University
Functional Programming in Java Part 2 CSE 219, Stony Brook University Functions as Objects The interface java.util.function.function To store a function (i.e., take a single argument and returns a
More informationJava 8 Stream Performance Angelika Langer & Klaus Kreft
Java 8 Stream Performance Angelika Langer & Klaus Kreft objective how do streams perform? explore whether / when parallel streams outperfom seq. streams compare performance of streams to performance of
More informationCOMP6700/2140 Stream Pipelines
COMP6700/2140 Stream Pipelines Alexei B Khorev Research School of Computer Science, ANU April 2017 Alexei B Khorev (RSCS, ANU) COMP6700/2140 Stream Pipelines April 2017 1 / 28 Topics 1 Idioms of Stream
More informationCOURSE 5 PROGRAMMING III OOP. JAVA LANGUAGE
COURSE 5 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Generics Defining a generic Run-time behavior Collections List Set Map COUSE CONTENT Collections Utilities classes Aggregate Operations
More informationProject Lambda: Functional Programming Constructs and Simpler Concurrency in Java SE 8
Project Lambda: Functional Programming Constructs and Simpler Concurrency in Java SE 8 Michael Cui Principle Engineer, Java Platform Group Oracle Corporation 1 The following is intended to outline our
More informationJava 8 Stream Performance Angelika Langer & Klaus Kreft
Java 8 Stream Performance Angelika Langer & Klaus Kreft agenda introduction loop vs. sequential stream sequential vs. parallel stream Stream Performance (2) what is a stream? equivalent of sequence from
More informationIndex. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309
A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48
More informationOverview of Java 8 Parallel Streams (Part 1)
Overview of Java 8 Parallel s (Part 1) Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University
More informationΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ
ΠΑΡΑΡΤΗΜΑ «Β» ΠΙΝΑΚΑΣ ΠΛΑΝΟΥ ΕΚΠΑΙΔΕΥΣΗΣ Α/Α ΠΕΡΙΓΡΑΦΗ ΕΚΠΑΙΔΕΥΣΗΣ ΘΕΜΑΤΙΚΕΣ ΕΝΟΤΗΤΕΣ 1. Java SE8 Fundamentals What Is a Java Program? Introduction to Computer Programs Key Features of the Java Language
More informationHigher-Order Sequential Operations
Chapter 9 Higher-Order Sequential Operations Many of the operations we wish to perform over lists have common structure. In this chapter, we investigate the most common of these patterns and how we can
More informationJava 8 Lambdas & Streams Angelika Langer
Java 8 Lambdas & Streams Angelika Langer objective understand lambda expressions learn about method references explore the stream API get a feeling for its performance model Lambdas & Streams in Java 8
More informationLambdas & Streams: Taking the Hard Work Out of Bulk Operations in Java SE 8.
Lambdas & Streams: Taking the Hard Work Out of Bulk Operations in Java SE 8 Simon Ritter Head of Java Evangelism Oracle Corporation Twitter: @speakjava 1 Concurrency in Java Project Lambda java.util.concurrent
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data
More informationCS 10: Problem solving via Object Oriented Programming Winter 2017
CS 10: Problem solving via Object Oriented Programming Winter 2017 Tim Pierson 260 (255) Sudikoff Streams Agenda 1. Streaming data 2. Java streams 2 Streams allow us to process things as they come Stream
More informationJava SE 8 New Features
Java SE 8 New Features Duration 2 Days What you will learn This Java SE 8 New Features training delves into the major changes and enhancements in Oracle Java SE 8. You'll focus on developing an understanding
More informationPractical Concurrency. Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Practical Concurrency Agenda Motivation Java Memory Model Basics Common Bug Patterns JDK Concurrency Utilities Patterns of Concurrent Processing Testing Concurrent Applications Concurrency in Java 7 2
More information1z0-813.exam.28q 1z0-813 Upgrade to Java SE 8 OCP (Java SE 6 and all prior versions)
1z0-813.exam.28q Number: 1z0-813 Passing Score: 800 Time Limit: 120 min 1z0-813 Upgrade to Java SE 8 OCP (Java SE 6 and all prior versions) Exam A QUESTION 1 Given the code fragment: What is the result?
More informationLecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011
Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions
More informationEE/CSCI 451: Parallel and Distributed Computation
EE/CSCI 451: Parallel and Distributed Computation Lecture #7 2/5/2017 Xuehai Qian Xuehai.qian@usc.edu http://alchem.usc.edu/portal/xuehaiq.html University of Southern California 1 Outline From last class
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationMicrosoft. Microsoft Visual C# Step by Step. John Sharp
Microsoft Microsoft Visual C#- 2010 Step by Step John Sharp Table of Contents Acknowledgments Introduction xvii xix Part I Introducing Microsoft Visual C# and Microsoft Visual Studio 2010 1 Welcome to
More informationChair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: concurrency Outline Java threads thread implementation sleep, interrupt, and join threads that return values Thread synchronization
More informationSynchronization SPL/2010 SPL/20 1
Synchronization 1 Overview synchronization mechanisms in modern RTEs concurrency issues places where synchronization is needed structural ways (design patterns) for exclusive access 2 Overview synchronization
More informationRefactoring to Functional. Hadi Hariri
Refactoring to Functional Hadi Hariri Functional Programming In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs,
More informationLesson 3-4: Using Collectors
Lesson 3-4: Using Collectors Collector Basics A Collector performs a mutable reduction on a stream Accumulates input elements into a mutable result container Results container can be a List, Map, String,
More informationOverview: The OpenMP Programming Model
Overview: The OpenMP Programming Model motivation and overview the parallel directive: clauses, equivalent pthread code, examples the for directive and scheduling of loop iterations Pi example in OpenMP
More informationJava 8 Programming for OO Experienced Developers
www.peaklearningllc.com Java 8 Programming for OO Experienced Developers (5 Days) This course is geared for developers who have prior working knowledge of object-oriented programming languages such as
More information6. Java Errors and Exceptions. Errors, runtime-exceptions, checked-exceptions, exception handling, special case: resources
129 6. Java Errors and Exceptions Errors, runtime-exceptions, checked-exceptions, exception handling, special case: resources Errors and Exceptions in Java 130 Errors and exceptions interrupt the normal
More information6. Java Errors and Exceptions
Errors and Exceptions in Java 6. Java Errors and Exceptions Errors and exceptions interrupt the normal execution of the program abruptly and represent an unplanned event. Exceptions are bad, or not? Errors,
More informationECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective
ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part II: Data Center Software Architecture: Topic 3: Programming Models Piccolo: Building Fast, Distributed Programs
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 15/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 30 Java 8! Lambdas and streams in Java 8 1 Java 8:
More informationList are immutable Lists have recursive structure Lists are homogeneous
WORKING WITH LISTS val fruit = List("apples", "oranges", "pears") val nums: List[Int] = List(1, 2, 3, 4) val diag3 = List( List(1, 0, 0), List(0, 1, 0), List(0, 0, 1) ) val empty = List() List are immutable
More informationJava Overview An introduction to the Java Programming Language
Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationA brief introduction to OpenMP
A brief introduction to OpenMP Alejandro Duran Barcelona Supercomputing Center Outline 1 Introduction 2 Writing OpenMP programs 3 Data-sharing attributes 4 Synchronization 5 Worksharings 6 Task parallelism
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationMicrosoft Visual C# Step by Step. John Sharp
Microsoft Visual C# 2013 Step by Step John Sharp Introduction xix PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2013 Chapter 1 Welcome to C# 3 Beginning programming with the Visual
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationJava SE 8 Programmer I and II Syballus( Paper codes : 1z0-808 & 1z0-809)
Page1 Java SE 8 Programmer 1, also called OCJA 8.0 Exam Number: 1Z0-808 Associated Certifications: Oracle Certified Associate, Java SE 8 Programmer Java Basics Highlights of the Certifications Define the
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationEfficient Java (with Stratosphere) Arvid Heise, Large Scale Duplicate Detection
Efficient Java (with Stratosphere) Arvid Heise, Large Scale Duplicate Detection Agenda 2 Bottlenecks Mutable vs. Immutable Caching/Pooling Strings Primitives Final Classloaders Exception Handling Concurrency
More informationJava Concurrency. Towards a better life By - -
Java Concurrency Towards a better life By - Srinivasan.raghavan@oracle.com - Vaibhav.x.choudhary@oracle.com Java Releases J2SE 6: - Collection Framework enhancement -Drag and Drop -Improve IO support J2SE
More informationDeclarative Concurrency (CTM 4)
Declarative Concurrency (CTM 4) Carlos Varela Rensselaer Polytechnic Institute Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL November 21, 2014 C. Varela; Adapted with permission from
More informationIntroduction to Functional Programming in Java 8
1 Introduction to Functional Programming in Java 8 Java 8 is the current version of Java that was released in March, 2014. While there are many new features in Java 8, the core addition is functional programming
More informationJava Live Lab. Course Outline. Java Live Lab. 20 Jun 2018
Course Outline 20 Jun 2018 Contents 1. Course Objective 2. Expert Instructor-Led Training 3. ADA Compliant & JAWS Compatible Platform 4. State of the Art Educator Tools 5. Award Winning Learning Platform
More informationIntroduction to Spark
Introduction to Spark Outlines A brief history of Spark Programming with RDDs Transformations Actions A brief history Limitations of MapReduce MapReduce use cases showed two major limitations: Difficulty
More informationJava 9 New features 8/11/2017 Iason Dimitrios Rodis
Java 9 New features 8/11/2017 Iason Dimitrios Rodis 2 Java 9 - New features Release date: September 21st 2017 Features: Java 9 REPL (JShell) Factory Methods for Immutable List, Set, Map and Map.Entry Private
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationRoland Mast Sybit GmbH Agiler Software-Architekt Scrum Master
SOLID mit Java 8 Roland Mast Sybit GmbH Agiler Software-Architekt Scrum Master roland.mast@sybit.de Roland Mast Sybit GmbH Agiler Software-Architekt roland.mast@sybit.de SOLID und Uncle Bob Single responsibility
More informationJVM ByteCode Interpreter
JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first
More informationKafka Streams: Hands-on Session A.A. 2017/18
Università degli Studi di Roma Tor Vergata Dipartimento di Ingegneria Civile e Ingegneria Informatica Kafka Streams: Hands-on Session A.A. 2017/18 Matteo Nardelli Laurea Magistrale in Ingegneria Informatica
More informationPrinciples of Software Construction: Objects, Design, and Concurrency
Principles of Software Construction: Objects, Design, and Concurrency Part 3: Design case studies Performance Charlie Garrod Michael Hilton School of Computer Science 1 Administriva Homework 4b due Thursday,
More informationQuick start. Robert Bachmann & Dominik Dorn. JSUG Meeting #63
1.. Java 8 Quick start Robert Bachmann & Dominik Dorn JSUG Meeting #63 Outline: What s new in Java 8 2 Interface additions and lambda syntax (r) Library additions (r) Nashorn (d) Type annotations (d) VM
More informationIntel Thread Building Blocks, Part II
Intel Thread Building Blocks, Part II SPD course 2013-14 Massimo Coppola 25/03, 16/05/2014 1 TBB Recap Portable environment Based on C++11 standard compilers Extensive use of templates No vectorization
More informationChapter 32 Multithreading and Parallel Programming
Chapter 32 Multithreading and Parallel Programming 1 Objectives To get an overview of multithreading ( 32.2). To develop task classes by implementing the Runnable interface ( 32.3). To create threads to
More informationCS 10: Problem solving via Object Oriented Programming. Streams
CS 10: Problem solving via Object Oriented Programming Streams Agenda 1. Streaming data 2. Java streams 2 Streams allow us to process things as they come Stream movie vs. file Stream (Ne1lix) Data produc=on
More informationProgramming Languages Third Edition. Chapter 9 Control I Expressions and Statements
Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE
More informationParallelization Strategy
COSC 6374 Parallel Computation Algorithm structure Spring 2008 Parallelization Strategy Finding Concurrency Structure the problem to expose exploitable concurrency Algorithm Structure Supporting Structure
More informationJava (8) for C++ Programmers
Java (8) for C++ Programmers Technion - Israel Institute of Technology Oren Afek, Natan Bagrov - March 2017 236703 - Object-Oriented Programming 1 Why Java? Object-oriented (even though not purely ) Portable
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationJava Collections The Force Awakens.
Java Collections The Force Awakens Darth @RaoulUK Darth @RichardWarburto Collection Problems Java Episode 8 & 9 Persistent & Immutable Collections HashMaps Collection bugs 1. 2. 3. Element access (Off-by-one
More informationBuilding Java Programs Chapter 19
Building Java Programs Chapter 19 Functional Programming with Java 8 Copyright (c) Pearson 2016. All rights reserved. What is FP? functional programming: A style of programming that emphasizes the use
More informationThe Pig Experience. A. Gates et al., VLDB 2009
The Pig Experience A. Gates et al., VLDB 2009 Why not Map-Reduce? Does not directly support complex N-Step dataflows All operations have to be expressed using MR primitives Lacks explicit support for processing
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages
More informationCopyright 2012, Oracle and/or its affiliates. All rights reserved.
1 Field guide to Java collections Mike Duigou (@mjduigou) Java Core Libraries 2 Required Reading Should have used most at some point List, Vector, ArrayList, LinkedList, Arrays.asList Set, HashSet, TreeSet
More informationShared state model. April 3, / 29
Shared state April 3, 2012 1 / 29 the s s limitations of explicit state: cells equivalence of the two s programming in limiting interleavings locks, monitors, transactions comparing the 3 s 2 / 29 Message
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationParallelization Strategy
COSC 335 Software Design Parallel Design Patterns (II) Spring 2008 Parallelization Strategy Finding Concurrency Structure the problem to expose exploitable concurrency Algorithm Structure Supporting Structure
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza
More informationPatterns of Parallel Programming with.net 4. Ade Miller Microsoft patterns & practices
Patterns of Parallel Programming with.net 4 Ade Miller (adem@microsoft.com) Microsoft patterns & practices Introduction Why you should care? Where to start? Patterns walkthrough Conclusions (and a quiz)
More informationClojure Concurrency Constructs. CSCI 5828: Foundations of Software Engineering Lecture 12 10/02/2014
Clojure Concurrency Constructs CSCI 5828: Foundations of Software Engineering Lecture 12 10/02/2014 1 Goals Cover the material presented in Chapters 3 & 4 of our concurrency textbook! Books examples from
More informationCS 351 Design of Large Programs Programming Abstractions
CS 351 Design of Large Programs Programming Abstractions Brooke Chenoweth University of New Mexico Spring 2019 Searching for the Right Abstraction The language we speak relates to the way we think. The
More informationCPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia
CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple
More informationLambda Expressions and Java 8 Streams. Jan Trienes, adapted by Th. Dorssers, Pieter van den Hombergh. Contents of this talk.
Java 8 s and Java 8 van den Hombergh Fontys Hogeschool voor Techniek en Logistiek February 23, 2017 and /FHTenL s and Java 8 February 23, 2017 1/28 talk Expression and Internal/External Iteration Java
More informationUNIT 3
UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment
More informationNew Features in Java 8
New Features in Java 8 Lambda expressions Functional interfaces Streaming support for Collections Lambda expressions Are a block of java code with parameters Can be assigned to variables Can be executed
More informationA Transactional Model and Platform for Designing and Implementing Reactive Systems
A Transactional Model and Platform for Designing and Implementing Reactive Systems Justin R. Wilson A dissertation presented to the Graduate School of Arts and Sciences of Washington University in partial
More informationFast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview
Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3 Course Code: GK1965 Overview Java 8 Essentials for OO Developers is a three-day, fast-paced, quick start to Java 8 training
More informationPeter Sestoft. Java Precisely. Third Edition. The MIT Press Cambridge, Massachusetts London, England
Peter Sestoft Java Precisely Third Edition The MIT Press Cambridge, Massachusetts London, England Contents Preface Notational Conventions xi xii 1 Running Java: Compilation, Loading, and Execution 2 2
More informationOp>onal. The Mother of all Bikesheds. Stuart Marks Core Libraries Java PlaGorm Group, Oracle
Op>onal The Mother of all Bikesheds Stuart Marks Core Libraries Java PlaGorm Group, Oracle Copyright 2016, Oracle and/or its affiliates. All rights reserved. Op>onal The Mother of all Bikesheds What is
More information