I would like to do eager initialization of multiple singletons but开发者_开发问答 the initialization can take on the order of minutes so I would like the initialization to happen on a separate thread. Is there a way to do this?
http://tembrel.blogspot.com/2009/11/concurrently-initialized-singletons-in.html
Sure, just start an auxiliary Thread and let it do it. The easiest way is using SingletonHolder and doing anything which causes the initialization in the auxiliary Thread. Other threads will block if they try to access it before the initialization finishes, so everything works fine.
精彩评论