Basic HTML version of Foils prepared 17 Nov 97

Foil 10 Synchronization

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


1 In Java, two threads can communicate by accessing a shared variable (shared-memory model).
2 If two threads can both modify an object, that is, they can both execute a method that assigns to a shared variable, then the modifications must be synchronized.
3 This is easy - just declare the method to be synchronized!
4 This means that Java will ensure that only one thread executes the method at a time.
5 Suppose more than one thread can access an account:
6 public class Account
7 { int bankBalance; ...
  • public synchronized void CreditAcct(int amt)
  • { ... bankBalance += amt; ... }}

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 Wed Apr 1 1998