-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
rc1
-
sparc
-
solaris_2.6
Name: rmT116609 Date: 11/13/2001
java -version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java Hotspot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
The sample below shows the use of a timer that we use quite frequently in our
code. When it works as expected, my worker thread should wake up every 7
seconds and interrupt my timer thread causing it to reset. The timer should
never call retry(). This works fine under versions prior to jdk1.4.0-b3.
Under 1.4.0-b3 the retryTimer.interrupt() call doesn't interrupt the timer as
expected other than the first time my worker thread wakes up.
Requested additional info...
1.
javac ThreadTest.java
java ThreadTest
2.
import java.util.Date ;
public class ThreadTest extends Thread {
private RetryTimer retryTimer ;
private int retryPeriod ;
public ThreadTest(int retryPeriod) {
this.retryPeriod = retryPeriod ;
retryTimer = new RetryTimer(retryPeriod) ;
retryTimer.start() ;
}
public void retry() {
System.out.println(new Date(System.currentTimeMillis())+"...retry called...") ;
}
public void run() {
while(true) {
try {
sleep(7000) ;
System.out.println(new Date(System.currentTimeMillis())+"[run()] interrupting retry timer...") ;
retryTimer.interrupt() ;
} catch(InterruptedException ie) { System.out.println("error: "+ie.getMessage()) ; }
}
}
class RetryTimer extends Thread {
private int period ;
private boolean oldData ;
public RetryTimer(int p) {
period = p ;
oldData = true ;
setDaemon(true) ;
}
public void run() {
while(true) {
try {
oldData = true ;
sleep(period) ;
} catch(InterruptedException e) {
System.out.println(new Date(System.currentTimeMillis())+"[RetryTimer]interrupted!!!") ;
oldData = false ;
}
if(oldData)
retry() ;
}
}
}
public static void main(String[] args) {
(new ThreadTest(33000)).start() ;
}
}
3.
No error messages
4.
The output when run under jdk 1.4.0-b3 is as follows:
% java ThreadTest
Fri Nov 09 18:54:41 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:54:41 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:54:48 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:54:55 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:02 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:09 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:14 GMT 2001...retry called...
Fri Nov 09 18:55:14 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:55:16 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:23 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:30 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:37 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:44 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:47 GMT 2001...retry called...
Fri Nov 09 18:55:47 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:55:51 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:55:58 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:56:05 GMT 2001[run()]interrupting retry timer...
The expected output (obtained under jdk1.3.1-b24) is as follows:
% java ThreadTest
Fri Nov 09 18:58:58 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:58:58 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:05 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:05 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:12 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:12 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:19 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:19 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:26 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:26 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:33 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:33 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:40 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:40 GMT 2001[RetryTimer]interrupted!!!
Fri Nov 09 18:59:47 GMT 2001[run()]interrupting retry timer...
Fri Nov 09 18:59:47 GMT 2001[RetryTimer]interrupted!!!
java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)
$ % java -cp . ThreadTest
Tue Nov 13 11:45:32 PST 2001[run()] interrupting retry timer...
Tue Nov 13 11:45:32 PST 2001[RetryTimer]interrupted!!!
Tue Nov 13 11:45:39 PST 2001[run()] interrupting retry timer...
Tue Nov 13 11:45:39 PST 2001[RetryTimer]interrupted!!!
Tue Nov 13 11:45:46 PST 2001[run()] interrupting retry timer...
Tue Nov 13 11:45:46 PST 2001[RetryTimer]interrupted!!!
Tue Nov 13 11:45:53 PST 2001[run()] interrupting retry timer...
Tue Nov 13 11:45:53 PST 2001[RetryTimer]interrupted!!!
Tue Nov 13 11:46:00 PST 2001[run()] interrupting retry timer...
The problem is not reproducible on Windows 2000, Linux Redhat 6.2 using JDK1.4.0-beta3.
(Review ID: 135381)
======================================================================