proper usage of synchronized singleton?

前端 未结 10 741
长发绾君心
长发绾君心 2020-12-31 12:09

So I am thinking about building a hobby project, one off kind of thing, just to brush up on my programming/design.

It\'s basically a multi threaded web spider, upda

10条回答
  •  太阳男子
    2020-12-31 12:22

    Try the Bill Pugh solution of initialization on demand holder idiom. The solution is the most portable across different Java compilers and virtual machines. The solution is thread-safe without requiring special language constructs (i.e. volatile and/or synchronized).

    http://en.wikipedia.org/wiki/Singleton_pattern#The_solution_of_Bill_Pugh

提交回复
热议问题