1 import java.util.Random;
3 public class ThreadSleep extends Thread {
4 public static final int N=5;
5 public static final int MOD_GC=2;
6 public static final int SLEEP_FIX=1000;
7 public static final int SLEEP_RND=500;
9 public static Random rnd;
18 myString = new String("LocObj#" + this.id);
22 sleep(SLEEP_FIX + rnd.nextInt(SLEEP_RND));
23 } catch(Exception e) {
24 System.out.println("Thread #" + this.id + " had an Exception");
29 System.out.println("(" + this.id + ") Thread woke up:");
30 System.out.println("(" + this.id + ")\t cnt=" + this.cnt + ", o=\'" + this.o + "\'");
31 System.out.println("(" + this.id + ")\t local=\'" + myString + "\'");
33 if (this.cnt % MOD_GC == 0) {
34 System.out.println("(" + this.id + ") Starting the GC now!...");
40 public static void main(String args[]) {
45 System.out.println("Creating and starting threads ...");
46 for (int i=0; i<N; i++) {
47 t = new ThreadSleep();
50 t.o = new String("GlobObj#" + i);
55 System.out.println("Finished.");