* tests/gc/ThreadJava.java: Added testcase.
authormichi <none@none>
Mon, 2 Apr 2007 17:20:38 +0000 (17:20 +0000)
committermichi <none@none>
Mon, 2 Apr 2007 17:20:38 +0000 (17:20 +0000)
* tests/gc/ThreadSleep.java: Added testcase.

--HG--
branch : exact-gc

tests/gc/ThreadJava.java [new file with mode: 0644]
tests/gc/ThreadSleep.java [new file with mode: 0644]

diff --git a/tests/gc/ThreadJava.java b/tests/gc/ThreadJava.java
new file mode 100644 (file)
index 0000000..16995fb
--- /dev/null
@@ -0,0 +1,41 @@
+public class ThreadJava extends Thread {
+       public static final int N=5;
+       public static final int SLEEP=200;
+       public static final int LEN=20;
+
+       public void run() {
+               while (true) {
+                       double d = Math.sqrt(Math.PI);
+                       String s = Double.toString(d);
+                       double e = Double.parseDouble(s);
+                       double f = Math.pow(e, 2);
+                       long  l1 = Math.round(f);
+                       long  l2 = Math.round(Math.PI);
+                       if (l1 != l2)
+                               System.out.println("What is going on???");
+               }
+       }
+
+       public static void main(String args[]) {
+               ThreadJava t = null;
+
+               System.out.println("Creating and starting threads ...");
+               for (int i=0; i<N; i++) {
+                       t = new ThreadJava();
+                       t.start();
+               }
+               t = null;
+
+               System.out.println("Sending Main-Thread to sleep ...");
+               try {
+                       Thread.sleep(SLEEP);
+               } catch (Exception e) {
+                       System.out.println("Exception while sleeping!");
+               }
+
+               System.out.println("Forcing a collection ...");
+               System.gc();
+
+               System.out.println("Finished.");
+       }
+}
diff --git a/tests/gc/ThreadSleep.java b/tests/gc/ThreadSleep.java
new file mode 100644 (file)
index 0000000..535b35f
--- /dev/null
@@ -0,0 +1,57 @@
+import java.util.Random;
+
+public class ThreadSleep extends Thread {
+       public static final int N=5;
+       public static final int MOD_GC=2;
+       public static final int SLEEP_FIX=1000;
+       public static final int SLEEP_RND=500;
+
+       public static Random rnd;
+
+       public int id;
+       public int cnt;
+       public Object o;
+
+       public void run() {
+               String myString;
+
+               myString = new String("LocObj#" + this.id);
+
+               while (true) {
+                       try {
+                               sleep(SLEEP_FIX + rnd.nextInt(SLEEP_RND));
+                       } catch(Exception e) {
+                               System.out.println("Thread #" + this.id + " had an Exception");
+                       }
+
+                       this.cnt++;
+
+                       System.out.println("(" + this.id + ") Thread woke up:");
+                       System.out.println("(" + this.id + ")\t cnt=" + this.cnt + ", o=\'" + this.o + "\'");
+                       System.out.println("(" + this.id + ")\t local=\'" + myString + "\'");
+
+                       if (this.cnt % MOD_GC == 0) {
+                               System.out.println("(" + this.id + ") Starting the GC now!...");
+                               System.gc();
+                       }
+               }
+       }
+
+       public static void main(String args[]) {
+               ThreadSleep t = null;
+
+               rnd = new Random();
+
+               System.out.println("Creating and starting threads ...");
+               for (int i=0; i<N; i++) {
+                       t = new ThreadSleep();
+                       t.id = i;
+                       t.cnt = 0;
+                       t.o = new String("GlobObj#" + i);
+                       t.start();
+               }
+               t = null;
+
+               System.out.println("Finished.");
+       }
+}