Class Note for CMPSCI 691 at UMass(12)
Class Note for CMPSCI 691 at UMass(12)
Popular in Course
Popular in Department
This 4 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Massachusetts taught by a professor in Fall. Since its upload, it has received 18 views.
Reviews for Class Note for CMPSCI 691 at UMass(12)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CMPSCI 691W Parallel and Concurrent Programming Spring 2006 Lecture 4 February 13 Lecturer Emery Berger Scribe Matthew Marzillz39 41 Concurrency in Java 0 Unlike CC7 Java has built in concurrency support 0 Various concurrency patterns available 411 Java Objects and Concurrency 0 Every Java Object has a lock 0 Very convenient but obvious space overhead 0 Can always lock an object With synchronized reserved word 0 JVM implements 7thin locllts77 status bit With every object7 0 or 17 only 1 if ever locked Bene t No accidental double locking Bene t Unlocks implicit7 these are Scoped Locks Bene t Thread speci c data becomes private local data to object 412 Built in CV objwait objWaitlong timeout objnotify objnotifyall 413 Using Java Threads 0 Simply Extend Thread 0 implement run method 0 call start on the object 0 Each thread has name7 priority7 and more httpjavasuncomj2sel3docsapijavalangThreadhtml 4 1 4 2 Lecture 4 February 13 414 Note on Priority 0 Unlike UNIX7 higher priority higher valuel setPriorityint7 getPriorityO7 example setPriorityThreadMAXPRIORITY If any thread is runnable at level i7 run instead of any thread less than i o Fixed priority scheduling7 although not guaranteed to always hold Use for performance reasons7 NOT safety Java will not change priority levels on you 42 Concurrency and Java 15 aka Tiger 0 Built on Doug Lea7s concurrency library 421 More Concurrency Constructs o Semaphores Ordinary counting acquireO7 tryAcquireO7 release Fair FIFO ordering o Linked Blocking Queue Blocks on put if full7 Blocks on take if empty Allows for producer consumer threads to add and remove work from a shared structure Linked implementation7 queue does not need a limit Does allow for max capacity WebServer example7 through put declines after some number of clients Solution Use Blocking Queue7 reject new clients by setting capacity of pipeline 0 Array Blocking Queue Blocks on put if full7 Blocks on take if empty Same idea7 except an array implementation Ideal for xed number of tasks 0 Synchornus Queue Each put waits for a take7 Also called a Rendezvous channel If you come back from a put you can be sure there was a take CSP Communicating Sequential Processes Tony Hoare7 inspired a language called OCCAM 0 Priority Blocking Queue Unbounded Queue7 based on heap Head item with 7lowest priority7 Useful for concurrent simulation applications Lecture 4 February 13 43 0 Delay Queue Time based scheduling queue Only expired elements can be removed Head Element that expired furthest into the past Element is expired when its getDelayTimeUnit method returns 0 1 Useful for simulators or when managing objects with timeouts 0 Copy on Write ArrayList Mutations on this list copy the entire backing array updating one element Cost of copying array useful when traversals vastly overwhelm new changes useful when you do not want to synchronize traversals o Exchanger Simple rendezvous Each thread gives object to exchange gets other yours exchangeri exchangemine o Barrier all threads reach synch point before continuing 7Barrier7 Very common for loops and scienti c apps Also for SOR Successive Over Relaxation aka Gaussian Smoothing Each location gets possibly weighted average of neighboring locations Image processing convolutions etc Barrier code example in slides o FutureTask Asynchronously executes some function to compute value run get cancel isDone Way to set up synch points and check if Future is complete if fiisDoneO vl figet v2 giget waits for tasks to complete 43 Thread Pools 0 Group of always living threads used repeatedly 0 Example Servers don7t create or destroy threads too costly 0 Instead keep a 7pool7 of threads and take a thread when a new task arrives o Bene t Faster with many tasks 0 Also limits max threads 44 Lecture 4 February 13 44 Further Links 0 Concurrent Java 15 Package Listing httpjavaisunicomj2se1i5i0docsapijavautilconcurrentpackage summaryihtml 0 Info about OCCAM htthWWWiW0tugiorgoccam 0 Original Slides for this lecture httpWWWicsiumassiedu emeryclassescmpsci691Wspring0061ecturescmpsci691W1ecture04 javaipdf
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'