I'm confused about this part in java -
During java classloader system loads the class file it allocates memory for different variables and methods present in the class file - like for new object memory gets allocated during runtime . But in case of static variables and methods in the class how and when memory gets allocated ? - Please help.
The memory is allocated when the classloader
loads the class
. It's a shared memory space accessible by all the instance of the class
and the class itself. Therefore unsafe to use a static
variable in multithreading
environment. Solution to static
variable in multithreading
environment is to make it final
as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.