由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - a synchonized problem!
相关主题
question: how to implement thisjava 依赖注入和反射是必须掌握的吗?
请教一个动态cast的问题java gc之前有没有办法得到notification?
basic java questionone way to show result windows while using VJ++
static getInstance()WSAD能用WAS做开发调试环境么?
我脑袋短路,大家来帮一下:Does anyone know where I can find this?
thread safe Singleton 的几种方法?get System environment variable
看到一个关于singleton的面试题display problem - maybe simple
面试的一些题目synchronization 锁住了什么?
相关话题的讨论汇总
话题: minstance话题: foo话题: problem话题: static
进入Java版参与讨论
1 (共1页)
o*******a
发帖数: 46
1
public class Foo{
private static Foo mInstance;

public static Foo getInstance(){
if(mInstance == null){
synchronized(Foo.class){
if(mInstance == null){
mInstance = new Foo();
}
}
}
return mInstance;
}
}
Will this work in all environments? If not, under what condition will this
fail? ?
xt
发帖数: 17532
2
I don't see any problem with it.
s*****g
发帖数: 1
3
make default constr private

【在 o*******a 的大作中提到】
: public class Foo{
: private static Foo mInstance;
:
: public static Foo getInstance(){
: if(mInstance == null){
: synchronized(Foo.class){
: if(mInstance == null){
: mInstance = new Foo();
: }
: }

m******t
发帖数: 2416
4
Google "Double Checked Locking Is Broken".

【在 o*******a 的大作中提到】
: public class Foo{
: private static Foo mInstance;
:
: public static Foo getInstance(){
: if(mInstance == null){
: synchronized(Foo.class){
: if(mInstance == null){
: mInstance = new Foo();
: }
: }

c*****t
发帖数: 1879
5
Good reading. Never realized that such tiny problem could have
such complicated answer :) Re-ordering can be so evil.

【在 m******t 的大作中提到】
: Google "Double Checked Locking Is Broken".
1 (共1页)
进入Java版参与讨论
相关主题
synchronization 锁住了什么?我脑袋短路,大家来帮一下:
如何在eclipse 里set java running environment的paththread safe Singleton 的几种方法?
start up tomcat problem看到一个关于singleton的面试题
IBM JRE6.0面试的一些题目
question: how to implement thisjava 依赖注入和反射是必须掌握的吗?
请教一个动态cast的问题java gc之前有没有办法得到notification?
basic java questionone way to show result windows while using VJ++
static getInstance()WSAD能用WAS做开发调试环境么?
相关话题的讨论汇总
话题: minstance话题: foo话题: problem话题: static