I am working on a group project in which we have several static constants declared in a Worker class. Multiple threads of this worker are spawned and our java application seems to be using a huge amount of memory. I am wondering if this is a result of each thread allocating more of these static constants, but I am not sure.
Share
No, there is only one instance of a static variable per ClassLoader.
However, it is important to realize that this doesn’t mean that the value is automagically synchronized. If the threads are changing this value then it needs to be
synchronizedotherwise they could see different values according to race conditions.