Added thread limiting with queue and thread synchronization with locks.