Advertisement
Guest User

SINGLECOSTAM

a guest
Jun 16th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. public class Singleton {
  2.     private static final int NUMBER_OF_INSTANCES = 3;
  3.     private final static Collection<Singleton> instances = new ArrayList<Singleton>();
  4.     private final Iterator<Singleton> instancesIterator = getInstacesIterator();
  5.  
  6.     private Singleton() {};
  7.  
  8.     synchronized public static Singleton getInstance() {
  9.         tryToAllocateNewInstances();
  10.         return instancesIterator.next();
  11.     }
  12.  
  13.     private static void tryToAllocateNewInstances() {
  14.         if (instances.size() < NUMBER_OF_INSTANCES)
  15.             instances.add(new Singleton());
  16.     }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement