Wednesday, 11 September 2013

Any idea on how can this exercise can be solved ? don't know if it should be used synchronized methods or so, thanks

Any idea on how can this exercise can be solved ? don't know if it should
be used synchronized methods or so, thanks

/**
* Java programming exercise Add to class Counter the methods stop, resume,
* restart and finish, making respectively the counting towards up to stop,
* resume where it stopped, return to 0 (stopped or not) and finish
* definitively. Observation: Do not use methods like interrupt, suspend,
* resume, stop, etc., inherited from class Thread.
**/
class Counter extends Thread {
private int n = 0;
private boolean running = true;
private boolean active = true;
private static int number;
public void run() {
while (running) {
if (active)
System.out.println(n++);
}
}
}

No comments:

Post a Comment