This question : java static variable and process
Is there a way I can achieve sharing static variables between multiple processes ? For instance by writing a custom class loader that loads the same class from the disk.
This question : java static variable and process
Is there a way I can achieve sharing static variables between multiple processes ? For instance by writing a custom class loader that loads the same class from the disk.
No. It is not possible.
Each process is in a separate address space. One process cannot see anything in another processes address space. This applies to all processes, not just Java processes.
The only way for one process to see something in another processes address space is if the 2 processes have a common shared memory segment. In C / C++ it is possible to do that ... if you are careful with the inter-process synchronization.
In Java, the shared memory approach is not practical:
static variables that you can use from Java code.Classloaders don't help. A classloader in one java process / address space loads classes into that address space. Other processes can't see them, and they can't see the corresponding static variables.
You could do it by using a database in which you store your variables, and all VM instances should read and write to this base for those variables.