JAVA静态方法的同步问题~~~~~~~~~~~~~

来源:互联网 发布:淘宝进销存哪个好 编辑:程序博客网 时间:2024/06/07 20:02

一直被同步搞得晕头转向,今天遇到了要写静态方法,总担心会不会有同步问题,结果看了以下一席话,豁然开朗~~

 

Every method of java will have a stack, and every invokation on thatmethod will have it's own 'stack frame'. So the locale data of onemethod invokation will not affect others.

Please do not confuse 'synchronization' with 'atomic'.

If one static method is synchronized, JVM will use the Class as the lock. If not, it acts as an instance method.

 

意思是说,JAVA的每个方法每次调用都有一个栈,所以方法里面的变量不会相互影响~~~

原创粉丝点击