[size=medium]我们经常会写一些util,helper类,
而一般这些类的方法都静态的,这在许多时候是很方便的
但是需要注意在可能的多线程环境下,
这些类尽量不要有属性字段, 如果确定要有(这在有时候也很有用),
要保证在方法中不修改这个属性字段的值,
不然在多线程环境下可能造成线程意外的相互影响,
还可以使用final修饰这个属性字段使其不可变,
就像我们经常使用的:
private final static Logger logger...
如果需要使用属性字段,而且又可能要改变它的值,最好就不要使用静态类方法了.
[/size]
而一般这些类的方法都静态的,这在许多时候是很方便的
但是需要注意在可能的多线程环境下,
这些类尽量不要有属性字段, 如果确定要有(这在有时候也很有用),
要保证在方法中不修改这个属性字段的值,
不然在多线程环境下可能造成线程意外的相互影响,
还可以使用final修饰这个属性字段使其不可变,
就像我们经常使用的:
private final static Logger logger...
如果需要使用属性字段,而且又可能要改变它的值,最好就不要使用静态类方法了.
[/size]