package verwaltung;

import java.util.Random;

/*
 * Created on Jul 5, 2004
 */

/**
 * @author oliver
 * @since Jul 5, 2004
 */
public class Person implements Runnable {
    
    private String name;
    
    public Person(String name) {
        this.name = name;
    }
    
    public String toString() {
        return this.name;
    }
    
    public void run() {
        arbeite();
    }

    public void arbeite() {
        try {
            for (int i = 0; i <= new Random().nextInt(3); i++) {
                Thread.sleep(1000);
                machePause();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            System.err.println("beim Schlafen gestoert\n" + e);
        }
    }
    
    private void machePause() throws InterruptedException {
        //System.out.println(this.name + " macht Pause.");
        Thread.sleep(500);          // a small pause of 500 ms
    }

    public static void main(String[] args) throws InterruptedException {
        Person[] team = { new Person("Hase"), new Person("Hugo") };
        for (int i = 0; i < team.length; i++) {
            Thread thread = new Thread(team[i]);
            thread.start();
            Thread.sleep(4000);     // wait a few seconds
        }
    }
    
}
