java.util.Timer doesn't work

F

FET

Hi all,
I have an application that displays a Swing GUI. The application
writes its logs to a certain file. I would like to have a thread that
checks the file every, say 10 seconds, and if it is found to be
deleted, creates a new file. I have made a class that extends
TimerTask and in the run method, it calls file.exists() and
file.createNewFile(). Then I have set timer.schedule ( task, 0,
10000). But the code never gets called.

Should I just use plain ol' awt threads ? I think Timers is a more
sophisticated mechanism. But it doesn't seem to be working.

Please advise.

Thanks in advance.

Best regards.
 
A

Andrew Thompson

C

Chris Smith

FET said:
I have an application that displays a Swing GUI. The application
writes its logs to a certain file. I would like to have a thread that
checks the file every, say 10 seconds, and if it is found to be
deleted, creates a new file. I have made a class that extends
TimerTask and in the run method, it calls file.exists() and
file.createNewFile(). Then I have set timer.schedule ( task, 0,
10000). But the code never gets called.

As Andrew said, please post a complete example that fails, including the
code to prove that the timer task is never called (println or whatever).
This should work.
Should I just use plain ol' awt threads ? I think Timers is a more
sophisticated mechanism. But it doesn't seem to be working.

There's no such concept as "AWT threads". Plain old Java threads would
work, but you're right that java.util.Timer is a better idea. Let's see
if we can fix that.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top