JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Software Design » Effective Java  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
話題被移動
該話題已被移動 - morchory , 2003-10-03 01:40
如果您尚不清楚該話題被移動的原因,請參考論壇規則以及本版公告或者聯系本版版主。
本主題所含的標籤
無標籤
作者 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 [Re:metavige]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-10-01 21:48 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Singleton: 2 ways to create the singleton object instance,
(1) Like demo program, declare a static final field and initialize immediately.
(2) Create on getInstance method.

Method (2) allows you do "lazy" creation, created only when you needed.

There are also thread safety issue.
Sometime, if you choice method (2), you may need sychronized to make sure thread safe.

My question is, if you choice method (1), do you still need to worry about thread safety problem ?
It seems to me that even on "static statement", you are not guarantee thread-safe.


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
15557 [精華] [Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 metavige 887 2003-10-01 15:24
13393 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 ymshin 21 2003-10-01 15:42
13402 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 metavige 72 2003-10-01 15:55
13353 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 T55555 563 2003-10-01 21:48
13393 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 Duncan 428 2003-10-01 22:21
13487 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 etman 862 2003-10-29 10:40
13131 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 Duncan 294 2003-10-30 16:13
13180 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 etman 160 2003-10-30 16:18
13075 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 Duncan 275 2003-10-30 18:53
13247 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 etman 281 2003-10-30 22:32
13008 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 metavige 120 2003-10-31 09:39
13244 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 etman 98 2003-10-31 10:06
13984 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 metavige 143 2003-10-31 13:12
13745 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 ingramchen 161 2003-10-01 22:45
4972 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 koji 190 2008-07-02 14:01
4415 Re:[Effective Java] 條款2 : 以 private 建構式厲行 singleton (單件)性質 YuLimin 11 2008-10-05 21:51
» JWorld@TW »  Software Design » Effective Java

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8