Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as text by berat ( 17 years ago )
public final class Counter {
private static long value = 0;
private static long Max=100;
public  static synchronized long getValue() {
return value;
}
public static synchronized long increment() {
	if (value >= Max){
		//throw new IllegalStateException("counter overflow");
		System.out.println("value 1 "+value);
		return decrement();
	}
	else
		System.out.println("value 2 "+value);
		return ++value;
}
public static synchronized long decrement(){
	if(value <=0){
		//throw new IllegalStateException("counter overflow");
		return increment();
	}
	else
		return --value;
}
public static void main(String [] args)
{
	for(;;){
	increment();
	//System.out.println(""+decrement());
	}
}
}

 

Revise this Paste

Your Name: Code Language: