Q) Whats the use of declaring variable as a volatile..?
The keyword volatile shows its power when it comes to multi thread environment.If your program is single thread volatile will not show any impact.
In multi thread environment each thread will keep a copy of variables, if you declare a variable as volatile them JVM will keep this variable in main memory instead of thread local memory.
The keyword volatile shows its power when it comes to multi thread environment.If your program is single thread volatile will not show any impact.
In multi thread environment each thread will keep a copy of variables, if you declare a variable as volatile them JVM will keep this variable in main memory instead of thread local memory.
No comments:
Post a Comment