Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:43:26+00:00 2026-05-14T14:43:26+00:00

I’m using JPoller to detect changes to files in a specific directory, but it’s

  • 0

I’m using JPoller to detect changes to files in a specific directory, but it’s missing files because they end up with a timestamp earlier than their actual creation time. Here’s how I test:

public static void main(String [] files)
{
    for (String file : files)
    {
        File f = new File(file);
        if (f.exists())
        {
            System.err.println(file + " exists");
            continue;
        }

        try
        {
            // find out the current time, I would hope to assume that the last-modified
            // time on the file will definitely be later than this
            System.out.println("-----------------------------------------");
            long time = System.currentTimeMillis();

            // create the file
            System.out.println("Creating " + file + " at " + time);
            f.createNewFile();

            // let's see what the timestamp actually is (I've only seen it <time)
            System.out.println(file + " was last modified at: " + f.lastModified());

            // well, ok, what if I explicitly set it to time?
            f.setLastModified(time);
            System.out.println("Updated modified time on " + file + " to " + time + " with actual " + f.lastModified());
        }
        catch (IOException e)
        {
            System.err.println("Unable to create file");
        }
    }
}

And here’s what I get for output:

-----------------------------------------
Creating test.7 at 1272324597956
test.7 was last modified at: 1272324597000
Updated modified time on test.7 to 1272324597956 with actual 1272324597000
-----------------------------------------
Creating test.8 at 1272324597957
test.8 was last modified at: 1272324597000
Updated modified time on test.8 to 1272324597957 with actual 1272324597000
-----------------------------------------
Creating test.9 at 1272324597957
test.9 was last modified at: 1272324597000
Updated modified time on test.9 to 1272324597957 with actual 1272324597000

The result is a race condition:

  1. JPoller records time of last check as xyz…123
  2. File created at xyz…456
  3. File last-modified timestamp actually reads xyz…000
  4. JPoller looks for new/updated files with timestamp greater than xyz…123
  5. JPoller ignores newly added file because xyz…000 is less than xyz…123
  6. I pull my hair out for a while

I tried digging into the code but both lastModified() and createNewFile() eventually resolve to native calls so I’m left with little information.

For test.9, I lose 957 milliseconds. What kind of accuracy can I expect? Are my results going to vary by operating system or file system? Suggested workarounds?

NOTE: I’m currently running Linux with an XFS filesystem. I wrote a quick program in C and the stat system call shows st_mtime as truncate(xyz...000/1000).

UPDATE: I ran the same program I have above on Windows 7 with NTFS and it does maintain full millisecond accuracy. The MSDN link @mdma provided further notes that FAT filesystems is accurate for creates with 10 ms resolution but for access is only accurate to 2 seconds. Thus, this is truly OS dependent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:43:27+00:00Added an answer on May 14, 2026 at 2:43 pm

    Filesystems do not store time precisely, and often not at millisecond resolution, e.g. FAT has a 2-second resolution for creation time, and NTFS can delay updating the last access time by up to an hour. (details on MSDN.) Although not in your case, in general, there is also the problem of synchronizing clocks if the file is created on another computer.

    It seems this might be an issue for the JPoller folks, since this is where the time handling logic is. Until it’s fixed, you could workaround this by manually setting the last modified time of each file written to be +4 seconds from the actual time – +4 is an arbitrary value that should be larger than the resolution of the filesystem you are working on. When the files are written to the file system, they will be rounded down, but by less than the value you have added. Not pretty, but it will work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The release() isn't allowed to cause the close() to fail.… May 15, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer As mentioned in the FAQ page "How do I find… May 15, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer Yes, take a look at the Cargo plugin for maven:… May 15, 2026 at 12:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.