开发者

How to do eager initialization of singleton in a separate thread?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜