View | Details | Raw Unified | Return to bug 64155
Collapse All | Expand All

(-)java/org/apache/tomcat/util/threads/TaskQueue.java (-5 / +7 lines)
Lines 66-79 Link Here
66
66
67
    @Override
67
    @Override
68
    public boolean offer(Runnable o) {
68
    public boolean offer(Runnable o) {
69
      //we can't do any checks
69
        //we can't do any checks
70
        if (parent==null) return super.offer(o);
70
        if (parent == null) return super.offer(o);
71
        // getPoolSize() is expensive call to AbstractQueuedSynchronizer acquire lock
72
        final int poolSize = parent.getPoolSize();
71
        //we are maxed out on threads, simply queue the object
73
        //we are maxed out on threads, simply queue the object
72
        if (parent.getPoolSize() == parent.getMaximumPoolSize()) return super.offer(o);
74
        if (poolSize == parent.getMaximumPoolSize()) return super.offer(o);
73
        //we have idle threads, just add it to the queue
75
        //we have idle threads, just add it to the queue
74
        if (parent.getSubmittedCount()<=(parent.getPoolSize())) return super.offer(o);
76
        if (parent.getSubmittedCount() <= poolSize) return super.offer(o);
75
        //if we have less threads than maximum force creation of a new thread
77
        //if we have less threads than maximum force creation of a new thread
76
        if (parent.getPoolSize()<parent.getMaximumPoolSize()) return false;
78
        if (poolSize < parent.getMaximumPoolSize()) return false;
77
        //if we reached here, we need to add it to the queue
79
        //if we reached here, we need to add it to the queue
78
        return super.offer(o);
80
        return super.offer(o);
79
    }
81
    }

Return to bug 64155