Hi Angela ,
Consider following Ex.
class BankAccount{
private int balance;
public synchronizec int ReadBalance(){
return balance;
}
public synchronized void UpdateBalance(int amount){
balance += amount;
}
}
class ReaderThread extends Thread{
BankAccount a;
ReaderThread (BankAccount a){
this.a = a;
}
public void run(){
while (true){
System.out.println("Balance=" + a.ReadBalance());
}//while
}
}//readerThread
class WriterThread extends Thread{
BankAccount a;
WriterThread (BankAccount a){
this.a = a;
}
public void run(){
while (true){
a.UpdateBalance(100);
System.out.println("Updated the Balance by Amount " + 100+ "$");
}//while
}
}//writerThread
public class Bank{
public static void main(
String args[]){
BankAccount a= new BankAccount();
ReaderThread t1= new ReaderThread (a); //1
WriterThread t2 = WriterThread (a); //2
t1.start();
t2.start();
}//main
}//bank
Now here both Reader and writer thread are working on the same object of the bank account ie.a. Both threads are in while loop, continuously reading or writing the account resp.
In this case, 'ReadBalance()' and 'UpdateBalance()' being synch., unless one thread finishes executing a method on the same bank account object'a', second can't.
I hope this helps.

Rashmi
[This message has been edited by Rashmi Gunjotikar (edited September 03, 2001).]