In my java module, multiple threads are calling string.intern()
, where each thread has their own copy of string
object. After calling string.intern()
these threads attempt to take a lock on that. However I have not found any documentation that discusses about thread safety of this intern().
My worry is, will I end up pushing duplicate string in thread pool?
EDIT : Let me explain the scenario.
The threads that I referred above are workitem threads generated by some job. These thread contain unique string identifier. Threads generated from a particular job will have same unique identifier. When these threads are spawned by job, they all point to same unique identifier. I am using this unique identifier as a lock to synchronize these threads. However, these workitem thread go through cycle of serialization and de-serialization. What I found that a unique identifier (which is string) of a de-serialized thread now no longer refers to a copy from thread pool. It has its own copy of unique identifier. Now my attempt to take lock on unique identifier is futile because I have more than one string objects of unique identifier.
string.intern() is an attempt to push this string object in thread pool and then use it as lock.