Re: Watching a directory for new files

2007-01-16 Thread robert lazarski
You can use just one thread just fine. Timer does have some drawbacks. Here's an example: ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(); // Do pings, starting now, with a 2 second delay ScheduledFuture ping = ses.scheduleWithFixedDelay(new PingTask

Re: Watching a directory for new files

2007-01-16 Thread David Kerber
Thanks for the suggestion. I don't need the extra capabilities or multiple threads for this app because of its simplicity and relatively low traffic rate, but I'll keep it in mind if I need to handle more traffic later on. Dave robert lazarski wrote: If you are using java 5 or higher, con

Re: Watching a directory for new files

2007-01-16 Thread robert lazarski
If you are using java 5 or higher, consider using ScheduledThreadPoolExecutor which is generally considered a replacement for Timer. Robert On 1/16/07, David Kerber <[EMAIL PROTECTED]> wrote: The javax.management.Timer class was rather more complex than I liked for the simple stuff I needed, bu

Re: Watching a directory for new files

2007-01-16 Thread David Kerber
The javax.management.Timer class was rather more complex than I liked for the simple stuff I needed, but while digging into it, I discovered the java.util.Timer class, which works great and is easy to implement, so thanks for putting me on the Timer track! Dave David Kerber wrote: Mikolaj

Re: Watching a directory for new files

2007-01-16 Thread David Kerber
Mikolaj Rydzewski wrote: David Kerber wrote: Thanks for the suggestion. One question about this technique: can I run the directory check loop directly in the contextInitialized event of the Listener, or is it mandatory to create a new thread? You can't make an infinite (almost) loop durin

Re: Watching a directory for new files

2007-01-16 Thread David Kerber
Caldarale, Charles R wrote: From: Tim Funk [mailto:[EMAIL PROTECTED] Subject: Re: Watching a directory for new files Various operating system allow hooks to do be notified when items in the filesystem change. But since we're using java - thats not the case here Tomcat does hav

RE: Watching a directory for new files

2007-01-16 Thread Caldarale, Charles R
> From: Tim Funk [mailto:[EMAIL PROTECTED] > Subject: Re: Watching a directory for new files > > Various operating system allow hooks to do be notified when > items in the filesystem change. But since we're using java > - thats not the case here Tomcat does have the c

Re: Watching a directory for new files

2007-01-16 Thread Mikolaj Rydzewski
David Kerber wrote: Thanks for the suggestion. One question about this technique: can I run the directory check loop directly in the contextInitialized event of the Listener, or is it mandatory to create a new thread? You can't make an infinite (almost) loop during processing an event. Using

Re: Watching a directory for new files

2007-01-16 Thread David Kerber
Thanks for the suggestion. One question about this technique: can I run the directory check loop directly in the contextInitialized event of the Listener, or is it mandatory to create a new thread? Dave Tim Funk wrote: Various operating system allow hooks to do be notified when items in t

Re: Watching a directory for new files

2007-01-16 Thread Tim Funk
Various operating system allow hooks to do be notified when items in the filesystem change. But since we're using java - thats not the case here so you need to something generic such as the following: Create a new ServletContextListener - this will run once one webapp loading. Have this spawn

Watching a directory for new files

2007-01-16 Thread David Kerber
Hi, Tomcatters - I have a working application to which I need to add a new function, where I need to watch a networked directory (not on the local tomcat server machine) for newly-appearing files, which I will then process. I need to have this done at intervals not exceeding about two minutes