Similar to Singleton class I want to create a Fiveton class which can create maximum 5 instances of the class. Different threads are trying to access instances of this class (hence getInstance method needs to be provided). However class is heavy so the instances must not be eagerly created i.e. created on demand.
Also contract is that threads are allotted instances in round robin fashion i.e. Thread no.1, 6, 11 get instance 1 of Fiveton object. If the instance is being used by a thread, they wait for the lock (it may be possible that thread 6 and 11 wait for instance 1 and thread 11 may get it but in no circumstance thread 11 should get instance 2). Similarly, Thread no. 2, 7, 12 should get instance 2.