Basic HTML version of Foils prepared 18 May 97

Foil 7 Synchronized Method and Blocks

From Java Tutorial - Spring 1997 Part 4: Multithreading, useful Java classes, I/O, Networking, and the future Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


Synchronized methods and blocks are implemented in the applet class by acquiring a lock before running
Code will therefore not run at the same time as other code that needs access to the same resource.
Each object has one lock associated with it and each class has exactly one lock
When invoked, a synchronized method waits until it can acquire the lock for the current instance (i.e., this); a static synchronized method waits to acquire the class lock
Lock is released when code is done executing
Locks are advisory
synchronized blocks specify the object on which to synchronize



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Thu Jan 8 1998