
CMPSCI 691W Parallel and Concurrent Programming Spring 2006
Lecture 4: February 13
Lecturer: Emery Berger Scribe: Matthew Marzilli
4.1 Concurrency in Java
•Unlike C/C++, Java has built in concurrency support;
•Various concurrency patterns available.
4.1.1 Java Objects and Concurrency
•Every Java Object has a lock
•Very convenient! but obvious space overhead
•Can always lock an object with synchronized reserved word
•JVM implements ’thin locks’, status bit with every object, 0 or 1, only 1 if ever locked
•Benefit+ No accidental double locking
•Benefit+ Unlocks implicit, these are Scoped Locks
•Benefit+ Thread specific data becomes private local data to object
4.1.2 Built in CV
•obj.wait();
•obj.wait(long timeout);
•obj.notify();
•obj.notifyall();
4.1.3 Using Java Threads
•Simply Extend Thread;
•implement run() method;
•call start() on the object;
•Each thread has name, priority, and more: http://java.sun.com/j2se/1.3/docs/api/java/lang/Thread.html;
4-1