TimerTask priority

L

Liz

Roedy Green said:

Thanks for the pointer, but I don't think I have
direct access to the thread. Here is my class which
I got most of from a book. It creates a JLabel and
puts the time of day in it, then updates it every
second. The prio of the thread it creates is 5 and
my graphics stuff runs at 6 (AWT-EventQueue-0) so
often the clock skips a few seconds.

See below the class listing for thread dump.
-------------------
public class ClockLabel extends JLabel implements ActionListener
{
SimpleDateFormat formatter = new SimpleDateFormat("E MM/dd/yy HH:mm:ss");
public ClockLabel(String text, int horizontalAlignment)
{
super(text,horizontalAlignment);
Timer t = new Timer(1000, this);
t.start();
}
public void actionPerformed(ActionEvent e)
{
setText((formatter.format(new Date())).toString());
}
}
--------------------
'd' means daemon, number is prio

Thread Group: system
Thread 0: d 10 Reference Handler
Thread 1: d 8 Finalizer
Thread 2: d 10 Signal Dispatcher
Thread 3: d 10 CompilerThread0
Thread 4: d 6 AWT-Windows
Thread 5: * 6 AWT-EventQueue-0
Thread 6: 5 AWT-Shutdown
Thread 7: d 5 TimerQueue
Thread 8: d 10 Java2D Disposer
Thread 9: 5 DestroyJavaVM
 
R

Roedy Green

The prio of the thread it creates is 5 and
my graphics stuff runs at 6 (AWT-EventQueue-0) so
often the clock skips a few seconds.

perhaps an easier way would be to lower the priority of the AWT
thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top