Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

thread safety of java.io.File.

833299Jun 27 2011 — edited Jul 4 2011
Encountered a strange problem when working on a small piece code that is supposed to tally up the number of files, sub-directories and total sizes for a given list of directories using java.io.File. Because the list could be long, the initial version of the code used multiple threads, where each thread responsible for the accounting of a directory off the list. But different runs would yield different results, and some of the results are definitely erroneous (e.g. saying a particular directory contains 0 files, 0 sub-dirs, and 0 sizes when it is known for fact that the directory has quite some number of entries). The logic of the code doesn't seem to be incorrect, so it seems the only explanation is that the java.io.File is not thread safe. However, the java API for this class doesn't say anything about its thread safety. So is this class thread unsafe? Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2011
Added on Jun 27 2011
9 comments
3,517 views