UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2005-10-08 10:32 AM

manjuWicky
Member
From: Kandy
Registered: 2005-10-06
Posts: 2

Re: Synchronization Problem

Tell me the synchronization problem in the programme below and tell me how to modify the code accordingly so it will run properly. This programme is created for JDK 1.5 and tell me how to make it run with 1.4 . Please Reply as fast as you can.
Thanks

public class Bank{
 
     public static Integer acc=new Integer(10000);

     public static void main(String args[]){

	Customer cust1 = new Customer(acc,true);
	Customer cust2 = new Customer(acc,false);

	cust1.start();
	cust2.start();

	System.out.println("The account balance is" + acc );

	while(true);

	}

  }

public class Customer extends Thread{

	private Integer acc;
	private boolean add;

     public Customer(Integer acc,boolean add){

	this.acc = acc;
	this.add=add;
     }

    public void run(){
		
	if(add)
		acc +=10000;
	else
		acc -=10000;
	
	System.out.println("The balance is**" + acc);
    
       }
}

Offline

Board footer

Powered by FluxBB