感谢两位仁兄的指点,让我找到了答案。
不过还是请问banq一个问题,如果按照绝对线程安全的标准,那么java里面的很多类比如Vector、Hashtable是不是都不是线程安全的了。如果不按照绝对的标准,那么就像在JavaRanch论坛里面提到的,是不是某些类可以保证它内部的线程安全我们就可以认为它是有条件的线程安全,这个是JavaRanch的一个讨论,就是关于您所说的Are java constructors thread safe?
http://www.coderanch.com/t/232106/threads/java/thread-safety-concern-constructors
如果按照Dave Landers所说的,题目中的Point是不是可以认为它可以保证内部的线程安全呢?
一下引用Dave Landers的论述:
Since a constructor is only run while the object is being created, thread safety of the constructor itself is not an issue. This is because two threads can't create the same object. If they are creating objects, they will create different ones.
In order for an object to be constructed (and thus have some combination of constructors invoked) somebody has to make a call to new.
While that is going on, other threads can not get a reference to that object until it is constructed (exception -see below). And in any case when another gets the instance, it can not invoke the constructor. A second threads can not invoke any constructor on the same object instance.
Exception: What I said above about "other threads can not get a reference till it is constructed" is not strictly true. It is true enough for the explaination above, but it still has a hole. The reason is all wrapped up in the Java Memory Model. Its the same reason that Double Checked Locking doesn't work in Java. Don't need to go into that into too much detail here.
当然,他也承认他所说的构造方法是线程安全的并非十分严格,如果按照他所说的不严格的标准是否可以认为Point也是线程安全的呢?
[该贴被cugxw于2012-10-21 01:39修改过]