Java Concurrency Overview

Slides:



Advertisements
Similar presentations
Isti upit iskazan na različite načine 2 - Zamena NOT IN (SELECT...) izraza
Advertisements

Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Concurrency.
CSC Multiprocessor Programming, Spring, 2011 Outline for Chapter 5 – Building Blocks – Library Classes, Dr. Dale E. Parson, week 5.
©SoftMoore ConsultingSlide 1 Appendix D: Java Threads "The real payoff of concurrent execution arises not from the fact that applications can be speeded.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 4: Threads.
1 CS2200 Software Development Lecture: Multi-threading II A. O’Riordan, 2009.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Java 5 Threading CSE301 University of Sunderland Harry Erwin, PhD.
1Semaphore A special type of lock. –Similar to lock as it can be used to prevent access to shared data when the data is locked. –A lock that has a value.
CS 2110: Parallel Programming A brief intro to: Parallelism, Threads, and Concurrency.
Threads in Java1 Concurrency Synchronizing threads, thread pools, etc.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Collage of Information Technology University of Palestine Advanced programming MultiThreading 1.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Status of the vector transport prototype Andrei Gheata 12/12/12.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
Java Threads 1 1 Threading and Concurrent Programming in Java Queues D.W. Denbo.
Working in the Background Radan Ganchev Astea Solutions.
Practice Session 8 Blocking queues Producers-Consumers pattern Semaphore Futures and Callables Advanced Thread Synchronization Methods CountDownLatch Thread.
Synchronizing threads, thread pools, etc.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
Threads in Java1 Concurrency Synchronizing threads, thread pools, etc.
Java8 Released: March 18, Lambda Expressions.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
Thread Pools CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
L6: Threads “the future is parallel” COMP206, Geoff Holmes and Bernhard Pfahringer.
…in java DThread Pools x. Thread Pools: Why? Source code updates – copy/paste of run/runnable method for each thread is exhausting There is overhead to.
Producer/Consumer CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Distributed and Parallel Processing George Wells.
Java.util.concurrent package. concurrency utilities packages provide a powerful, extensible framework of high-performance threading utilities such as.
A brief intro to: Parallelism, Threads, and Concurrency
Prepared by Oussama Jebbar
Thread Pools (Worker Queues) cs
Asynchronous Programming
A Scheme concurrency library
Thread Pools (Worker Queues) cs
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Taking Java from purely OOP by adding “functional level Programming”
Isti upit iskazan na različite načine
Lecture 28 Concurrent, Responsive GUIs
Java Algorithms.
Programi zasnovani na prozorima
Functional Programming with Java
4.1 Vizualni (grafički) HTML uređivači
Java 8 Java 8 is the biggest change to Java since the inception of the language Lambdas are the most important new addition Java is playing catch-up: most.
Chapter 4: Threads & Concurrency
KREIRANJE OBJEKATA.
Uvod u programiranje - matematika – X predavanje
14 UNUTRAŠNJE I ANONIMNE KLASE
Arrays and strings -1 (nizovi i znakovni nizovi)
Element form Milena Kostadinović.
Ključne reči,identifikatori, konstante i promenljive
Osnovni simboli jezika Pascal
MagistralA (bus) Milan Milovanovic I6.
Naredbe u php-u.
21 Threads.
A few of the more significant changes and additions. James Brucker
Chapter 4: Threads & Concurrency
Lambda Expressions.
Threads in Java James Brucker.
Parallel Programming with ForkJoinPool Tasks in Java
Software Engineering and Architecture
Introduction – Core Java Tutorial Introduction – Created by JavaTechWorld.com.
CMSC 202 Threads.
Parallel Programming with ForkJoinPool Tasks in Java
Presentation transcript:

Java Concurrency Overview

Pregled kursa Osnove threadova u Java-i Threading best practice i concurrency package Fork Join frejmvork Paralelni streamovi i lambde

Osnove threadova u Java-i Threadovi / niti omogućavaju pisanje programa sa paralelnim tokovima izvršavanja Kreiranje threadova Klasa Thread Nasledjivanje klase Thread I override metode run() Interfejs Runnable Implementacija interfejsa se prosledjuje kao parametar konstruktoru Thread-a Runnable je funkcionalni interfejs od Java 8

Glavni izazovi u radu sa thredovima Zajednicki podaci (shared data) Cekanje – minimizovati (po mogucstvu eliminisati) portrebu za sinhronizacijom I cekanjem Threadovi rade razlicitim brzinama, razlicite kolicine posla I dodeljivanje procesora je nepredvidivo Kolicina posla po jednom threadu– treba da bude dovoljno velika da bi opravdala paralelizaciju inace ce raditi sporije nego u jednom thread-u

Primeri BasicCounterThreads BasicRunnableThreads TwoCounters TwoSharedCounterThreads

Cosumer Producer Consumer/Producer Wait / notify

Blocking Queue

Thread Pool

Zasto java.util.concurrency Josh Bloch, Effective Java 2nd Edition, Item 69: Prefer concurrency utilities to wait and notify Given the difficulty of using wait and notify correctly, you should use the higher-level concurrency utilities instead [...] using wait and notify directly is like programming in "concurrency assembly language", as compared to the higher-level language provided by java.util.concurrent. There is seldom, if ever, reason to use wait and notify in new code.

java.util.concurrent Zasto java.util.concurrent? Thread Pools, Blocking Queue ExecutorService interfejs Klase Callable i Future Kreiranje threadova pomocu factory klase Executors Executors.newFixedThreadPool() Executors.newCachedThreadPool() creates new threads as needed, but will reuse previously constructed threads when they are available.

Cyclic Barrier CyclicBarrier barrier = new CyclicBarrier(2); barrier.await();

Fork Join Framwork RecursiveAction RecursiveTask Common fork join pool Work stealing http://www.oracle.com/technetwork/articles/java/fork-join- 422606.html

Java Concurrent Animated https://sourceforge.net/projects/javaconcurrenta/

Lambda izrazi Lambda izrazi su skracena sintaksa za interfejse sa samo jednom metodom. Pogledati java.util.function Consumer Predicate Function BiFunction https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html

Stream-ovi Stream je sekvence elemenata nad kojima se mogu primeniti niz operacija (koje se najcesce zadaju pomocu lambda izraza) Stream podrzava intermediate I terminalne operacije

Parallel Streams & Lambdas Stream.stream() i Stream.parallelStream() foreach() - primeni na svaki element strima map() - transformisi elemente strima filter() - filtriraj elemente strima collect() - pretvori strim u kolekciju Ispod haube paralelnog strima je Fork Join frejmvork https://docs.oracle.com/javase/tutorial/collections/streams/parall elism.html http://winterbe.com/posts/2014/07/31/java8-stream-tutorial- examples/

Literatura Java Concurrency In Practice, Brian Goetz https://www.amazon.com/Java-Concurrency-Practice- Brian-Goetz/dp/0321349601