/**
* An Assignment thread continuously assigns its private value to
* a shared value.
*/
public class Assignment extends Thread
{
/** The value shared by all Assignment objects */
public static long sharedValue;
/** The private value of this Assignment object */
private long privateValue;
/**
* Creates an Assignment object with the given private value.
*
* @param privateValue the private value of the created Assignment object.
*/
public Assignment(long privateValue)
{
this.privateValue = privateValue;
}
/**
* Continuously assigns the private value of this Assignment object
* to the shared value of all Assignment objects.
*/
public void run()
{
while (true)
{
Assignment.sharedValue = this.privateValue;
}
}
}
/**
* A Print thread continuously prints the value of the value shared
* by all Assignment objects.
*/
public class Print extends Thread
{
/**
* Continuously prints the value of the value shared
* by all Assignment objects.
*/
public void run()
{
while (true)
{
System.out.println(Assignment.sharedValue);
}
}
}
public class Client
{
public static void main(String[] args)
{
Assignment zero = new Assignment(0);
Assignment max = new Assignment(Long.MAX_VALUE);
Print print = new Print();
zero.start();
max.start();
print.start();
}
}