This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See do need to record somewhere that you've already spawned a boss.
Then your code might look something like:Winston
Campbell Ritchie
Posts: 57453
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Winston Gutkowski wrote: . . . I'm not quite sure if I agree with Campbell's advice about making it a singleton . . .

Nor am I. I was offering it as a suggestion rather than advice.
An alternative is to have a static count variable in the Boss class; you only instantiate the class if it is 0. If you are multi‑threading, that method can allow several Boss objects to exist, if the constructor is accessed simultaneously by several threads. Again just a suggestion, rather than advice.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!