I am looking for some suggestions.
I have a class called FileMonitorNotifer.
The run() inside the class is used to loop over the registered files and see which have changed. It uses the Modified DateTimeStamp to determine if there was a change.
The code works fine. That is not the issue.
Basically, I run this java monitor process on an AIX box where the process runs to see if there are files in a specific directory, if there are 2 matching files in that dir it processes them, if not, it sleeps and runs again.
My issue happens after the sleep.
If two new files come into the directory at once while the java monitor process is a sleep they have the same DateTimeStamp.
When the run() gets to these 2 files and since the DTS has not changed the 2 files sit in this dir and I have to manually go in and touch the file for them to process.
Is there a better option for this?
I have heard of polling, but can that work for my situation.
If so, can someone give me a head start, any code snippets or articles would help.
Thanks in advance. Annie
private class FileMonitorNotifier extends TimerTask
public void run()
// Loop over the registered files and see which have changed.
// Uses the Modifed DateTimeStamp to determine if there was a change.
// Use a copy of the list in case listener wants to alter the
// list within its fileChanged method.
Collection files = new ArrayList (hmFiles.keySet());
for (Iterator i = files.iterator(); i.hasNext(); )
File file = (File) i.next();
long lastModifiedTime = ((Long) hmFiles.get (file)).longValue();
long newModifiedTime = file.exists() ? file.lastModified() : -1;
// Check if file has changed
if (newModifiedTime != lastModifiedTime)
// Register new modified time
hmFiles.put(file, new Long (newModifiedTime));
// Notify listeners
for (Iterator j = colListeners.iterator(); j.hasNext(); )
WeakReference reference = (WeakReference) j.next();
FileListener listener = (FileListener) reference.get();
// Remove from list if the back-end object has been GC'd
if (listener == null)