-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
7
-
x86
-
windows_7
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 Home Premium (No Service Packs Installed)
EXTRA RELEVANT SYSTEM CONFIGURATION :
Intel Core i7 CPU 2.93GHz Dual Core
64bit operating system
8GB RAM
A DESCRIPTION OF THE PROBLEM :
The Problem:
When running the below test application the ScheduledThreadPoolExecutor scheduled to run at a fixed rate of 3 milliseconds runs chaotically with frequent spikes of greater than 15 milliseconds. It should execute at a rate of every 3 milliseconds.
Interesting Details:
The problem is fixed when other large desktop applications are running at the same time as the test app, or when the application is running specifically in IntelliJ IDE... The problem almost always occurs when no other large applications are running.
Thank you for taking the time too look into this issue. Its really frustrating that I can't seem to get consistent timing using the SceduledThreadPoolExecutor class or the Timer class and really messes with animations.
REGRESSION. Last worked in version 7
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Make sure no other Java applications are running and other desktop applications are closed.
- Run the below test case through the command prompt not inside an IDE as this sometimes fixes the problem.
- Click and hold inside the JTextArea to start the ScheduledThreadPoolExecutor scheduled at a fixed rate of 3 milliseconds.
- Any times greater than 3.5 milliseconds will be flagged and printed to the JTextArea. You should notice frequent spikes of 15 milliseconds or greater.
- If you don't see significant time spikes and no other desktop applications are running most of the time restarting the computer brings back the problem.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to see times around 3 milliseconds between each execution as its normal for there to be some variation. However spikes of 15 milliseconds is way more variation then I'd expect and really makes it difficult to create smooth animations or other time sensitive tasks.
ACTUAL -
I see frequent spikes of 15 milliseconds between executions. 11 milliseconds greater then the expected time between executions. Even scheduling the threadpoolexecutor at slower times only increases the time of the unexpected spikes.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages were received.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
package testtime;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class TestTime extends JFrame {
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TestTime().setVisible(true);
}
});
}
JTextArea area = new JTextArea();
JScrollPane pane = new JScrollPane(area);
ScheduledThreadPoolExecutor executor;
public TestTime() {
setTitle("Test Case");
setSize(450, 300);
setAlwaysOnTop(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
area.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
area.setText("--Press and HOLD anywhere to start--\n\n" +
"--Release to stop the ScheduledThreadPoolExecutor--\n\n" +
"If time exceeds 3.5 milliseconds it will be printed here...\n\n" +
"------------------------------------\n\n");
executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleAtFixedRate(new Loop(), 0L, 3L, TimeUnit.MILLISECONDS);
}
@Override
public void mouseReleased(MouseEvent e) {
executor.shutdownNow();
}
});
area.setLineWrap(true);
area.setWrapStyleWord(true);
area.setText("--Press and HOLD anywhere to start--\n\n" +
"--Release to stop the ScheduledThreadPoolExecutor--\n\n" +
"If time exceeds 3.5 milliseconds it will be printed here...\n\n" +
"------------------------------------\n\n");
area.setFont(new Font("Arial", Font.PLAIN, 11));
area.setForeground(Color.red);
add(pane);
}
class Loop extends Thread {
long time = 0L;
@Override
public void run() {
long timeTaken = System.nanoTime() - time;
if(timeTaken > 3500000L) {
area.append(timeTaken+"(nanoseconds) -- "+(timeTaken/1000000L)+"(milliseconds)\n");
}
time = System.nanoTime();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Unfortunately I haven't found a practical way to bypass this bug. A few interesting details though....
- The 15 millisecond spikes appear to disappear when other large desktop applications are running at the same time as the test case.
- The 15 millisecond spikes NEVER occur while running the test case in IntelliJ IDE. But OFTEN occur when running the test case in NetBeans IDE or Eclipse IDE.
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 Home Premium (No Service Packs Installed)
EXTRA RELEVANT SYSTEM CONFIGURATION :
Intel Core i7 CPU 2.93GHz Dual Core
64bit operating system
8GB RAM
A DESCRIPTION OF THE PROBLEM :
The Problem:
When running the below test application the ScheduledThreadPoolExecutor scheduled to run at a fixed rate of 3 milliseconds runs chaotically with frequent spikes of greater than 15 milliseconds. It should execute at a rate of every 3 milliseconds.
Interesting Details:
The problem is fixed when other large desktop applications are running at the same time as the test app, or when the application is running specifically in IntelliJ IDE... The problem almost always occurs when no other large applications are running.
Thank you for taking the time too look into this issue. Its really frustrating that I can't seem to get consistent timing using the SceduledThreadPoolExecutor class or the Timer class and really messes with animations.
REGRESSION. Last worked in version 7
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Make sure no other Java applications are running and other desktop applications are closed.
- Run the below test case through the command prompt not inside an IDE as this sometimes fixes the problem.
- Click and hold inside the JTextArea to start the ScheduledThreadPoolExecutor scheduled at a fixed rate of 3 milliseconds.
- Any times greater than 3.5 milliseconds will be flagged and printed to the JTextArea. You should notice frequent spikes of 15 milliseconds or greater.
- If you don't see significant time spikes and no other desktop applications are running most of the time restarting the computer brings back the problem.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to see times around 3 milliseconds between each execution as its normal for there to be some variation. However spikes of 15 milliseconds is way more variation then I'd expect and really makes it difficult to create smooth animations or other time sensitive tasks.
ACTUAL -
I see frequent spikes of 15 milliseconds between executions. 11 milliseconds greater then the expected time between executions. Even scheduling the threadpoolexecutor at slower times only increases the time of the unexpected spikes.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages were received.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
package testtime;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class TestTime extends JFrame {
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TestTime().setVisible(true);
}
});
}
JTextArea area = new JTextArea();
JScrollPane pane = new JScrollPane(area);
ScheduledThreadPoolExecutor executor;
public TestTime() {
setTitle("Test Case");
setSize(450, 300);
setAlwaysOnTop(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
area.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
area.setText("--Press and HOLD anywhere to start--\n\n" +
"--Release to stop the ScheduledThreadPoolExecutor--\n\n" +
"If time exceeds 3.5 milliseconds it will be printed here...\n\n" +
"------------------------------------\n\n");
executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleAtFixedRate(new Loop(), 0L, 3L, TimeUnit.MILLISECONDS);
}
@Override
public void mouseReleased(MouseEvent e) {
executor.shutdownNow();
}
});
area.setLineWrap(true);
area.setWrapStyleWord(true);
area.setText("--Press and HOLD anywhere to start--\n\n" +
"--Release to stop the ScheduledThreadPoolExecutor--\n\n" +
"If time exceeds 3.5 milliseconds it will be printed here...\n\n" +
"------------------------------------\n\n");
area.setFont(new Font("Arial", Font.PLAIN, 11));
area.setForeground(Color.red);
add(pane);
}
class Loop extends Thread {
long time = 0L;
@Override
public void run() {
long timeTaken = System.nanoTime() - time;
if(timeTaken > 3500000L) {
area.append(timeTaken+"(nanoseconds) -- "+(timeTaken/1000000L)+"(milliseconds)\n");
}
time = System.nanoTime();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Unfortunately I haven't found a practical way to bypass this bug. A few interesting details though....
- The 15 millisecond spikes appear to disappear when other large desktop applications are running at the same time as the test case.
- The 15 millisecond spikes NEVER occur while running the test case in IntelliJ IDE. But OFTEN occur when running the test case in NetBeans IDE or Eclipse IDE.