Code example for BlockingQueue

Methods: offer, size

0
     */ 
    public synchronized void enqueue(final T object) {
        if (maxThreads <= 0) {
            return; 
        } 
        queue.offer(object);
        final int queueSize = queue.size();
        final int threadsSize = threads.size();
        if (threadsSize < maxThreads && threadsSize < queueSize) {
            // Start another thread 
            final WorkerThread thread = new WorkerThread();
            thread.setName("#" + (threadIndex++) + " " + name);
            threads.add(thread);
            thread.start();
        } 
    } 
 
    /** 
     * Enqueues all the given objects for processing 
     */ 
    public void enqueueAll(final Collection<T> objects) {