Hi,

I checked in some of my little bugfixes and some new classes that were not
yet checked in. Here is the changelog:

    * java/lang/ThreadLocal.java: new 1.2 class
    * java/lang/InheritableThreadLocal.java: new 1.2 class
    * vm/reference/java/lang/Thread.java: added example to use ThreadLocals
    * java/lang/Package.java: new 1.2 class (but no support in ClassLoader yet)
    * java/util/Timer.java: new 1.3 class
    * java/util/TimerTask.java: new 1.3 class
    * java/net/JarURLConnection.java: getCertificates returns a Certificate[]
    * java/security/ProtectionDomain.java: constructor should make the
    PermissionCollection read only

I would appreciate it if someone looked over these files to see if I
did anything stupid.

I did have a strange problem with java.util.Timer with gcj. Sometimes I
would get java.lang.IllegalMonitorStateException when testing it.
Could someone with a newer or cvs version of gcj (I have 2.95.2) try the
attached program with the java.util.Timer[Task] classes from cvs
(you have to compile them with jikes first to get class files)
and tell if you still get a IllegalMonitorException. I hope it is a bug
in gcj, but it might also very well be a bug in my code.

I have not yet checked in my beginning of java/util/jar and
java/net/URLClassLoader that I will clean up next and possibly merge with
the libgcj ones.

Cheers,

Mark

P.S. Two little notes on the build process:
- Since the javax directory is completely empty now we might want to
remove it from the Makefile (since cvs update -dP will remove the whole
directory now).
- Since java/text/DecimalFormat.java is missing (has it ever existed?)
I had to add java/text/MessageFormat.java to standard.omit.
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerTest {

    static private class TaskTest extends TimerTask {
        private final String name;

        TaskTest(String name) {
            this.name = name;
        }

        public void run() {
            System.out.println(name + ": " + new Date());
        }
    }

    public static void main(String args[]) {
    try {
        TimerTest test = new TimerTest();
        test.run();
        test = null;

        System.out.println("Done. Waiting 3 seconds...");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ie) {}
        System.out.println("Garbage collect");
        System.gc();
        System.out.println("Quit");
    } catch (Throwable t) {
        System.out.println("Oops: " + t);
        t.printStackTrace();
    }
    }

    public void run() {

        Timer timer = new Timer();
        TimerTask tasks[] = new TimerTask[10];
        for(int i = 1; i<=10; i++) {
            try{Thread.sleep(1000);}catch(InterruptedException ie){}
            System.out.println("Created task: " + i);
            tasks[i-1] = new TaskTest("Task-" + i);
            timer.schedule(tasks[i-1], 1000, i*1000);
        }

        System.out.println("All Tasks started, waiting 5 seconds...");
        try{Thread.sleep(5000);}catch(InterruptedException ie){}

        System.out.println("Cancel all tasks");
        for(int i = 0; i<10; i++) {
            try{Thread.sleep(1000);}catch(InterruptedException ie){}
            System.out.println("Canceling task: " + (i+1));
            tasks[i].cancel();
        }
        System.out.println("All tasks canceled");
    }
}

Reply via email to