Basic HTML version of Foils prepared 18 May 97

Foil 8 Threads and Synchronization - I

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


1 A Synchronized method provides a guarantee that the method is the only synchronized method in the object running at the time.
2 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(); }
3 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 ..}

in Table To:


© 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