I had problem X so I decided to do Y, and now I have a problem with Y. Can you help me with that?
amol skulkarni wrote:Strings could be used in multiple places in the code and a lock on the String will cause unnecessary deadlock which leads to undebuggable code issues.
File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine.
amol skulkarni wrote:Consider a fact that I need to write a file based on the String lock.String is the path to the file.A lock on the string would indicate that no other thread is working on the file.
amol skulkarni wrote:Sorry this is like a reply after years but this was an interesting topic ....
amol skulkarni wrote:Sorry this is like a reply after years but this was an interesting topic ....We used weak references to solve this issue. Object Pool when passed a String would return a weak reference. Over a period if there are no references to this object JVM cleans them up and the overhead of accumulation is automatically eliminated.