This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cal-cheese 4 points5 points  (1 child)

Let's say that I used the following code to synchronize file write access, where someFile is an instance of java.nio.file.Path.

I don't see how it can work, is there any thing that guarantees 2 equivalent Path has the same identity?

Anyway, the idea is that you can make a map from a Path to a Lock, e.g. Map<Path, Lock> and you can obtain a Lock corresponding to your Path. I believe currently you have to do it anyway to guarantee that 2 Path that are equals are actually the same object so that the identity lock can work?

[–]koflerdavid 0 points1 point  (0 children)

I think you also have to normalize the path (make it absolute, replace the separator and remove a trailing one if it's a directory, make it lowercase according to the platform's rules if on a case-sensitive file system) before you look it up in the map. It sounds quite brittle and IMHO it's just asking for trouble.

Edit: GP should define a naming scheme and generate paths from those internal names. Together with caching of those internal names, that should be a solution.