|
Prev: (www.stefsclothes.com)sell t-shirt,nike adidas shoes,bape,ugg,evisu,ed-hardy,bag(paypal accept)
Next: What is the quickest way to play sound?
From: Neil Coffey on 23 Jul 2008 00:04 Greg Stasica wrote: > public class DBQuery{ > > private static DBQuery dbQuery = null; > > public static DBQuery getInstance() > { > if (dbQuery == null) { > dbQuery = new DBQuery(); > } > return dbQuery; > } You do know that this getInstance() method isn't thread-safe, don't you? Neil
From: Arne Vajhøj on 27 Jul 2008 15:59 Neil Coffey wrote: > Greg Stasica wrote: > >> public class DBQuery{ >> >> private static DBQuery dbQuery = null; >> >> public static DBQuery getInstance() >> { >> if (dbQuery == null) { >> dbQuery = new DBQuery(); >> } >> return dbQuery; >> } > > You do know that this getInstance() method isn't thread-safe, don't you? At least he can get multiple DBQuery objects, but he should always get a valid DBQuery reference back. Arne
From: Arne Vajhøj on 27 Jul 2008 16:37 Mike Schilling wrote: > Arne Vajh�j wrote: >> Neil Coffey wrote: >>> Greg Stasica wrote: >>> >>>> public class DBQuery{ >>>> >>>> private static DBQuery dbQuery = null; >>>> >>>> public static DBQuery getInstance() >>>> { >>>> if (dbQuery == null) { >>>> dbQuery = new DBQuery(); >>>> } >>>> return dbQuery; >>>> } >>> You do know that this getInstance() method isn't thread-safe, don't >>> you? >> At least he can get multiple DBQuery objects, but he should always >> get a valid DBQuery reference back. > > I don't think that's guaranteed. There is some possibility that he'll > get a DBQuery that is not fully initialized, since the JVM is within > its rights to reorder the assignment to dbQuery with the statements in > the constructor. (Disclaimer; that was true in the original JVM > memory model. I don't know if the current one changes that.) I don't think the MM has changed regarding that. And that could be a problem as well. Could be, because I don't think we have seen the constructor. Arne
From: Neil Coffey on 11 Aug 2008 23:33 Mike Schilling wrote: >> At least he can get multiple DBQuery objects, but he should always >> get a valid DBQuery reference back. > > I don't think that's guaranteed. There is some possibility that he'll > get a DBQuery that is not fully initialized, since the JVM is within > its rights to reorder the assignment to dbQuery with the statements in > the constructor. (Disclaimer; that was true in the original JVM > memory model. I don't know if the current one changes that.) No, it doesn't -- au contraire, as time moves on we'll probably see more VMs implementing such optimisation. It's hard to say if this was what actually caused the anomaly the poster reported -- I have to admit you'd be extremely unlucky (but then out in the wild, the extremely unlikely does eventually occur...). It *is* a bug, so in absence of anything else to go on, I'd recommend correcting it as the first course of action. Neil
From: edmund yau on 12 Aug 2008 03:39
Neil Coffey 提到: > Mike Schilling wrote: > >>> At least he can get multiple DBQuery objects, but he should always >>> get a valid DBQuery reference back. >> >> I don't think that's guaranteed. There is some possibility that he'll >> get a DBQuery that is not fully initialized, since the JVM is within >> its rights to reorder the assignment to dbQuery with the statements in >> the constructor. (Disclaimer; that was true in the original JVM >> memory model. I don't know if the current one changes that.) > > No, it doesn't -- au contraire, as time moves on we'll probably see more > VMs implementing such optimisation. > > It's hard to say if this was what actually caused the anomaly the > poster reported -- I have to admit you'd be extremely unlucky (but > then out in the wild, the extremely unlikely does eventually occur...). > It *is* a bug, so in absence of anything else to go on, I'd > recommend correcting it as the first course of action. > > Neil IT manager 蛇頭鼠眼edmund yau (email擬似yautinho(a)hotmail.com) 全香港最濺IT Manager, 見你著西裝返工. 著得好過佢就問你夠竟點諗, 正小人, 痴撚線 5:00pm俾個job你做, 跟住就自己做到11點搞掂佢, 第2日就小你, 話你搞唔掂, 唔 撚洗放工呀 最撚柒就係呢條友啦, 搞個爛網出黎, 大家去睇下: 網址擬似www.funzy.com 有幾爛? 仆街, 用IE6開會死機架, 真係唔撚知用乜野skill可以寫撚到hang機. 成條team朝9晚10, 搞個爛網得個2個function仔, 唔係hang機就係死link, 仲話寫 web要都唔知乜撚野skill set, 食屎啦, 小學生寫個web都唔撚會hang機啦 個個同事想放工都要驚呢樣驚個樣, 你張你o的青春濺賣就唔撚好叫人一齊同你濺 賣, 人地都有屋企, 你唔撚放工就你o既事, 除撚左打工都唔撚知搞個web未, 屎坑關刀 大家多多張呢個網發佈出去, 聲討呢種小人 Counter 1 |