Java Reference
In-Depth Information
// this method should be overridden in every subclass
public void run() { }
// returns the name of this process
public String toString() {
return this .name;
// notifies the graphical user interface
public void repaint() {
this .notifyObservers("REPAINT");
The test case consists of the implementation of a simple client
application. Class Server extends class EventProcess adding a reference to the
graphical interface (the frame member variable). Clients invoke method
doService() to start the execution of a task. A task behaviour is implemented
in method run() and simply consists of switching the value of a Boolean
variable. When the task starts, the server raises the DOSERVICE event. When
it is completed, the server raises the WORKDONE event.
package parking;
public class Server extends EventProcess {
boolean working # false ; // true when the server is
// working the constructor
public Server(String name) {
super (name);
// The Client invoke this method to request the execution
// of a Server task.
public void doService() {
synchronized ( this ) { this .notify(); }
// this method implements the Server behaviour
public void run() {
while (alive)
try {
// waits for a request of execution from a Client
synchronized ( this ) { this .wait(); }
working # true ;
// notifies the Client that the task has been started
this .notifyObservers("DOSERVICE");
this .repaint();
// The Server receives a request of task execution.
// It simulates the task duration by suspending the
// thread for 1000 milliseconds
Search WWH ::

Custom Search