P
Paul J. Lucas
I've seen differing opinions on whether it will do as one would expect to do
something like:
synchronized ( myString.intern() ) {
// ...
}
that is: for a given, unique string (say "foo"), does String.intern() guarantee
that:
s.intern() == t.intern() iff s.equals( t )
assuming s != null && t != null? I.e., does it guarantee the same object for a
string composed of the same characters? If yes, then synchronizing on it should
work as one would expect, right?
The use case is to prevent concurrent access to a particular file, e.g.:
File f = ...;
synchoronzed ( f.getCanonicalPath().intern() ) {
// ...
}
If this will *not* work, why not? And how can I achieve what I want?
- Paul
something like:
synchronized ( myString.intern() ) {
// ...
}
that is: for a given, unique string (say "foo"), does String.intern() guarantee
that:
s.intern() == t.intern() iff s.equals( t )
assuming s != null && t != null? I.e., does it guarantee the same object for a
string composed of the same characters? If yes, then synchronizing on it should
work as one would expect, right?
The use case is to prevent concurrent access to a particular file, e.g.:
File f = ...;
synchoronzed ( f.getCanonicalPath().intern() ) {
// ...
}
If this will *not* work, why not? And how can I achieve what I want?
- Paul