× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



James,

Aha, and there it is:
while (!false);

That's what's eating up all your CPU. The Timer runs creates its own
thread so there's no need to keep the thread that your main () method is
running in alive. You then need to change your
timer_ = new Timer (true);
to
timer_ = new Timer (false);

With this param as "true", the Timer thread WILL end as soon as the main ()
thread ends.

Hope this helps,

Nigel Gay.




"James Perkins"
<jrperkinsjr@gmai
l.com> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc

21/08/2008 06:04 Subject
PM Re: Never Ending Java Program


Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.com>






Thanks for the info Joe.

Here is the test class that implements the FileListener interface that goes
with this. I'm still in my learning phase with Java and it seems every time
I think I have it figured out, there is one more thing pops up.

I will start with just changing the interval. All I really want to do with
this is fire a program call when a file is added to the directory. At this
point I'm just seeing if it's possible/feasible to do it this way.

public class Test implements FileListener {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test t = new Test();
DirectoryMonitor dirMon = new DirectoryMonitor(1000);
//FileMonitor dirMon = new FileMonitor(1000);
try {
dirMon.addDirectory(new IFSFile(new AS400("localhost",
"username", "password"), "/home"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dirMon.addListener(t);

while (!false);
}

public void fileAdded(IFSFile file) {
System.out.println("Added: " + file.getName());
}

public void fileChanged(IFSFile file) {
System.out.println("Changed: " + file.getName());
}

public void fileRemoved(IFSFile file) {
System.out.println("Removed: " + file.getName());
}

}


Thanks,
--
James R. Perkins

On Thu, Aug 21, 2008 at 12:33 PM, Joe Sam Shirah
<joe_sam@xxxxxxxxxxxxx>wrote:


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.

--
Thanks,
James R. Perkins

On Thu, Aug 21, 2008 at 9:30 AM, Thorbjørn Ravn Andersen <
thunderaxiom@xxxxxxxxx> wrote:

James Perkins skrev den 21-08-2008 17:27
I have ran it interactively and it was using about 120% of the CPU.
In
batch
it was around 11%.

How often do you run Thread.yield() and Thread.sleep() ?

--
Thorbjørn Ravn Andersen "... plus... Tubular Bells!"

--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.

--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.

--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.


--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.



********************************************************************************
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee; access to this
email by anyone else is unauthorised.

If you are not the intended recipient: (1) you are kindly requested
to return a copy of this message to the sender indicating that you
have received it in error, and to destroy the received copy; and (2)
any disclosure or distribution of this message, as well as any action
taken or omitted to be taken in reliance on its content, is prohibited
and may be unlawful.
********************************************************************************

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.