HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 114 Threads and Synchronization - I

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * Important Information in IMAGE

A Synchronized method provides a guarantee that the method is the only synchronized method in the object running at the time.
This is useful if the resource is contained completely in the object, and in general, no waiting for a resource is necessary. (The operation is contained completely in the method)
  • public synchronized void do_it() {
    • Do_my_stuff();
  • }
More fine-grained synchronization can be obtained by synchronizing on the particular object:
  • Object obj;
  • public void do_it() {
    • synchronized(obj) {
    • ... change the state of obj ...
    • }
    • ... do other time-consuming stuff ...
  • }



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 Tue Feb 18 1997