Hi James,
Your Timer invocation looks OK. The other thing that (always) matters,
aside from the interval frequency, is what the thread is actually doing;
that is, how intensive is and how long does DirectoryMonitorNotifier() run?
Clearly it's doing disk accesses, which are relatively slow. What does
the constructor do, since you're creating a new one every time. Just thread
frequency shouldn't account for 120% (interesting number) and 11 % of CPU
respectively. One of my favorite stories, although it doesn't involve
Timers or threads, has to do with a client running a third party package
that provided them with *18 hour* End of *Day* processing. Think about
that. Things got a lot better after we did a softwarectomy.
Another option, if the constructor is intense, is to use the same
DirectoryMonitorNotifier with its own yield/sleep thread(s).
I have Timers for several operations at various clients (happens that
none of them, so far, are AS/400 boxes ) and haven't seen problems.
However, typical frequencies are 5 - 10 minutes.
Joe Sam
Joe Sam Shirah -
http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum:
http://www.ibm.com/developerworks/java/
Just the JDBC FAQs:
http://www.jguru.com/faq/JDBC
Going International?
http://www.jguru.com/faq/I18N
Que Java400?
http://www.jguru.com/faq/Java400
----- Original Message -----
From: "James Perkins" <jrperkinsjr@xxxxxxxxx>
To: "Java Programming on and around the iSeries / AS400"
<java400-l@xxxxxxxxxxxx>
Sent: Thursday, August 21, 2008 2:06 PM
Subject: Re: Never Ending Java Program
Thorbjørn,
I'm using a TimerTask, so in the code I don't yield or sleep.
Here is what the constructor looks like.
public DirectoryMonitor(long interval) {
files_ = new HashMap();
dirs_ = new HashMap();
listeners_ = new ArrayList();
timer_ = new Timer(true);
timer_.schedule(new DirectoryMonitorNotifier(), 0, interval);
}
I got most of the code from some where, can't remember exactly. It might be
work re-working to implement Runnable and use Observer and Observable to
notify. I've never used TimerTask before so I don't know much about it.
As an Amazon Associate we earn from qualifying purchases.