diablo 1.6.0_07-b02, threads/interrupt

mocra Moc mmmocra9 at gmail.com
Wed May 19 18:53:26 UTC 2010


hello,
i think there is something like a bug in diablo-jdk 1.6.0_07-b02 with
threads/interrupt

following example should print something like

there is a life before death..
active...
active...
active...
active...
interrupt in sleep()
end

but unfortunately, the program stops within the catch-block

public class ThreadTest {
    public static void main(String[] args) {
        Thread t = new Thread() {
            public void run()
            {
                System.out.println( "there is a life before death.." );

                while (!isInterrupted() ) {
                    System.out.println( "active..."
);
                    try  {
                        Thread.sleep( 500 );
                        } catch ( InterruptedException e ) {
                            interrupt();
                            System.out.println( "interrupt in sleep()" );

                    }
                }
                System.out.println( "end" );
            }
        };
        t.start();
        try {
            Thread.sleep( 2000 );
        } catch (InterruptedException e) {}

        t.interrupt();
    }
}

but the output is:
there is a life before death..
active...
active...
active...
active...

so, IMO there is sum bug in interrupt()/isInterrupted(). within the
catch-block the interrupt-flag is set to false, so you have to set it
manually by interrupt(), but the program stops after interrupt() without
printing neither "interrupt in sleep" nor "end"

my system:
FreeBSD 8.0-RELEASE-p2 (i386)
java version "1.6.0_07"
Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
Diablo Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

also tried with another FreeBSD machine, with diablo-1.6.0_07-b02 too -
doesn't work

works fine on a fedora system with Java(TM) SE Runtime Environment (build
1.6.0_18-b07)


More information about the freebsd-java mailing list