corba/src/java.corba/share/classes/com/sun/corba/se/impl/orbutil/threadpool/ThreadPoolImpl.java
author chegar
Wed, 11 Nov 2015 11:31:21 +0000
changeset 33680 56aa0b79bf5a
parent 29937 c774371adf92
child 37620 230612715768
permissions -rw-r--r--
8140606: Update library code to use internal Unsafe Reviewed-by: alanb, mchung, psandoz, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
29937
c774371adf92 8048997: Enhance thread contexts in CORBA
msheppar
parents: 25862
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.orbutil.threadpool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    28
import java.io.IOException;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    29
import java.io.Closeable;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    30
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    31
import java.security.AccessController;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    32
import java.security.PrivilegedAction;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    33
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    34
import java.util.List;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    35
import java.util.ArrayList;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    36
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    37
import java.util.concurrent.atomic.AtomicInteger;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    38
import java.util.concurrent.atomic.AtomicLong;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    39
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.spi.orbutil.threadpool.NoSuchWorkQueueException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.spi.orbutil.threadpool.ThreadPool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.spi.orbutil.threadpool.Work;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.spi.orbutil.threadpool.WorkQueue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.orbutil.threadpool.WorkQueueImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import com.sun.corba.se.spi.monitoring.MonitoringConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import com.sun.corba.se.spi.monitoring.MonitoredObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.corba.se.spi.monitoring.MonitoringFactories;
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    51
import com.sun.corba.se.spi.orb.ORB;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    54
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    55
import com.sun.corba.se.impl.orbutil.ORBConstants;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    56
import com.sun.corba.se.spi.logging.CORBALogDomains;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    57
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
public class ThreadPoolImpl implements ThreadPool
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
{
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    60
    // serial counter useful for debugging
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    61
    private static AtomicInteger threadCounter = new AtomicInteger(0);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    62
    private static final ORBUtilSystemException wrapper =
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    63
        ORBUtilSystemException.get(CORBALogDomains.RPC_TRANSPORT);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    64
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    66
    // Any time currentThreadCount and/or availableWorkerThreads is updated
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    67
    // or accessed this ThreadPool's WorkQueue must be locked. And, it is
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    68
    // expected that this ThreadPool's WorkQueue is the only object that
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    69
    // updates and accesses these values directly and indirectly though a
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    70
    // call to a method in this ThreadPool. If any call to update or access
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    71
    // those values must synchronized on this ThreadPool's WorkQueue.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    private WorkQueue workQueue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    // Stores the number of available worker threads
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    private int availableWorkerThreads = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    // Stores the number of threads in the threadpool currently
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    private int currentThreadCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    // Minimum number of worker threads created at instantiation of the threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    private int minWorkerThreads = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    // Maximum number of worker threads in the threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    private int maxWorkerThreads = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    // Inactivity timeout value for worker threads to exit and stop running
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    private long inactivityTimeout;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    // Indicates if the threadpool is bounded or unbounded
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    private boolean boundedThreadPool = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    // Running count of the work items processed
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    // Set the value to 1 so that divide by zero is avoided in
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    // averageWorkCompletionTime()
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    95
    private AtomicLong processedCount = new AtomicLong(1);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    // Running aggregate of the time taken in millis to execute work items
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    // processed by the threads in the threadpool
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    99
    private AtomicLong totalTimeTaken = new AtomicLong(0);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    // Name of the ThreadPool
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    private String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    // MonitoredObject for ThreadPool
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    private MonitoredObject threadpoolMonitoredObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    // ThreadGroup in which threads should be created
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   108
    private ThreadGroup threadGroup;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   109
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   110
    Object workersLock = new Object();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   111
    List<WorkerThread> workers = new ArrayList<>();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
     * This constructor is used to create an unbounded threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    public ThreadPoolImpl(ThreadGroup tg, String threadpoolName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        inactivityTimeout = ORBConstants.DEFAULT_INACTIVITY_TIMEOUT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        maxWorkerThreads = Integer.MAX_VALUE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        workQueue = new WorkQueueImpl(this);
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   120
        threadGroup = tg;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        name = threadpoolName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        initializeMonitoring();
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
     * This constructor is used to create an unbounded threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
     * in the ThreadGroup of the current thread
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    public ThreadPoolImpl(String threadpoolName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        this( Thread.currentThread().getThreadGroup(), threadpoolName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
     * This constructor is used to create bounded threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    public ThreadPoolImpl(int minSize, int maxSize, long timeout,
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
                                            String threadpoolName)
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        minWorkerThreads = minSize;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        maxWorkerThreads = maxSize;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        inactivityTimeout = timeout;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        boundedThreadPool = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        workQueue = new WorkQueueImpl(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        name = threadpoolName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        for (int i = 0; i < minWorkerThreads; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
            createWorkerThread();
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        initializeMonitoring();
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   151
    // Note that this method should not return until AFTER all threads have died.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   152
    public void close() throws IOException {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   153
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   154
        // Copy to avoid concurrent modification problems.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   155
        List<WorkerThread> copy = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   156
        synchronized (workersLock) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   157
            copy = new ArrayList<>(workers);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   158
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   159
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   160
        for (WorkerThread wt : copy) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   161
            wt.close();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   162
            while (wt.getState() != Thread.State.TERMINATED) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   163
                try {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   164
                    wt.join();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   165
                } catch (InterruptedException exc) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   166
                    wrapper.interruptedJoinCallWhileClosingThreadPool(exc, wt, this);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   167
                }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   168
            }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   169
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   170
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   171
        threadGroup = null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   172
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   173
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   174
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    // Setup monitoring for this threadpool
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    private void initializeMonitoring() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        // Get root monitored object
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        MonitoredObject root = MonitoringFactories.getMonitoringManagerFactory().
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
                createMonitoringManager(MonitoringConstants.DEFAULT_MONITORING_ROOT, null).
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                getRootMonitoredObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
        // Create the threadpool monitoring root
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        MonitoredObject threadPoolMonitoringObjectRoot = root.getChild(
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
                    MonitoringConstants.THREADPOOL_MONITORING_ROOT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        if (threadPoolMonitoringObjectRoot == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
            threadPoolMonitoringObjectRoot =  MonitoringFactories.
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                    getMonitoredObjectFactory().createMonitoredObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
                    MonitoringConstants.THREADPOOL_MONITORING_ROOT,
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                    MonitoringConstants.THREADPOOL_MONITORING_ROOT_DESCRIPTION);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
            root.addChild(threadPoolMonitoringObjectRoot);
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        threadpoolMonitoredObject = MonitoringFactories.
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                    getMonitoredObjectFactory().
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                    createMonitoredObject(name,
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                    MonitoringConstants.THREADPOOL_MONITORING_DESCRIPTION);
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        threadPoolMonitoringObjectRoot.addChild(threadpoolMonitoredObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        LongMonitoredAttributeBase b1 = new
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            LongMonitoredAttributeBase(MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS,
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
                    MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS_DESCRIPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                public Object getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                    return new Long(ThreadPoolImpl.this.currentNumberOfThreads());
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
            };
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        threadpoolMonitoredObject.addAttribute(b1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
        LongMonitoredAttributeBase b2 = new
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
            LongMonitoredAttributeBase(MonitoringConstants.THREADPOOL_NUMBER_OF_AVAILABLE_THREADS,
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                    MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS_DESCRIPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                public Object getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                    return new Long(ThreadPoolImpl.this.numberOfAvailableThreads());
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
            };
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        threadpoolMonitoredObject.addAttribute(b2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        LongMonitoredAttributeBase b3 = new
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            LongMonitoredAttributeBase(MonitoringConstants.THREADPOOL_NUMBER_OF_BUSY_THREADS,
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
                    MonitoringConstants.THREADPOOL_NUMBER_OF_BUSY_THREADS_DESCRIPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
                public Object getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
                    return new Long(ThreadPoolImpl.this.numberOfBusyThreads());
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
            };
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        threadpoolMonitoredObject.addAttribute(b3);
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        LongMonitoredAttributeBase b4 = new
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            LongMonitoredAttributeBase(MonitoringConstants.THREADPOOL_AVERAGE_WORK_COMPLETION_TIME,
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
                    MonitoringConstants.THREADPOOL_AVERAGE_WORK_COMPLETION_TIME_DESCRIPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
                public Object getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
                    return new Long(ThreadPoolImpl.this.averageWorkCompletionTime());
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
            };
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        threadpoolMonitoredObject.addAttribute(b4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        LongMonitoredAttributeBase b5 = new
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            LongMonitoredAttributeBase(MonitoringConstants.THREADPOOL_CURRENT_PROCESSED_COUNT,
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
                    MonitoringConstants.THREADPOOL_CURRENT_PROCESSED_COUNT_DESCRIPTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
                public Object getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
                    return new Long(ThreadPoolImpl.this.currentProcessedCount());
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            };
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        threadpoolMonitoredObject.addAttribute(b5);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        // Add the monitored object for the WorkQueue
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        threadpoolMonitoredObject.addChild(
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
                ((WorkQueueImpl)workQueue).getMonitoredObject());
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
    // Package private method to get the monitored object for this
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    // class
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    MonitoredObject getMonitoredObject() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        return threadpoolMonitoredObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    public WorkQueue getAnyWorkQueue()
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        return workQueue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    public WorkQueue getWorkQueue(int queueId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        throws NoSuchWorkQueueException
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        if (queueId != 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            throw new NoSuchWorkQueueException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        return workQueue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
     * To be called from the workqueue when work is added to the
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
     * workQueue. This method would create new threads if required
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
     * or notify waiting threads on the queue for available work
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    void notifyForAvailableWork(WorkQueue aWorkQueue) {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   271
        synchronized (aWorkQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   272
            if (availableWorkerThreads < aWorkQueue.workItemsInQueue()) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                createWorkerThread();
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
                aWorkQueue.notify();
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   281
    private Thread createWorkerThreadHelper( String name ) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   282
        // Thread creation needs to be in a doPrivileged block
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   283
        // if there is a non-null security manager for two reasons:
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   284
        // 1. The creation of a thread in a specific ThreadGroup
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   285
        //    is a privileged operation.  Lack of a doPrivileged
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   286
        //    block here causes an AccessControlException
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   287
        //    (see bug 6268145).
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   288
        // 2. We want to make sure that the permissions associated
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   289
        //    with this thread do NOT include the permissions of
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   290
        //    the current thread that is calling this method.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   291
        //    This leads to problems in the app server where
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   292
        //    some threads in the ThreadPool randomly get
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   293
        //    bad permissions, leading to unpredictable
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   294
        //    permission errors (see bug 6021011).
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   295
        //
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   296
        //    A Java thread contains a stack of call frames,
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   297
        //    one for each method called that has not yet returned.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   298
        //    Each method comes from a particular class.  The class
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   299
        //    was loaded by a ClassLoader which has an associated
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   300
        //    CodeSource, and this determines the Permissions
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   301
        //    for all methods in that class.  The current
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   302
        //    Permissions for the thread are the intersection of
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   303
        //    all Permissions for the methods on the stack.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   304
        //    This is part of the Security Context of the thread.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   305
        //
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   306
        //    When a thread creates a new thread, the new thread
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   307
        //    inherits the security context of the old thread.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   308
        //    This is bad in a ThreadPool, because different
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   309
        //    creators of threads may have different security contexts.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   310
        //    This leads to occasional unpredictable errors when
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   311
        //    a thread is re-used in a different security context.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   312
        //
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   313
        //    Avoiding this problem is simple: just do the thread
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   314
        //    creation in a doPrivileged block.  This sets the
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   315
        //    inherited security context to that of the code source
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   316
        //    for the ORB code itself, which contains all permissions
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   317
        //    in either Java SE or Java EE.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   318
        WorkerThread thread = new WorkerThread(threadGroup, name);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   319
        synchronized (workersLock) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   320
            workers.add(thread);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   321
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   322
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   323
        // The thread must be set to a daemon thread so the
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   324
        // VM can exit if the only threads left are PooledThreads
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   325
        // or other daemons.  We don't want to rely on the
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   326
        // calling thread always being a daemon.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   327
        // Note that no exception is possible here since we
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   328
        // are inside the doPrivileged block.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   329
        thread.setDaemon(true);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   330
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   331
        wrapper.workerThreadCreated(thread, thread.getContextClassLoader());
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   332
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   333
        thread.start();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   334
        return null;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   335
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   336
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   337
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
     * To be called from the workqueue to create worker threads when none
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
     * available.
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    void createWorkerThread() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   343
        final String name = getName();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   344
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   345
            try {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   346
                if (System.getSecurityManager() == null) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   347
                    createWorkerThreadHelper(name);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                } else {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   349
                    // If we get here, we need to create a thread.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   350
                    AccessController.doPrivileged(
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   351
                            new PrivilegedAction() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   352
                        public Object run() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   353
                            return createWorkerThreadHelper(name);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   354
                        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   355
                    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   356
                    );
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                }
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   358
            } catch (Throwable t) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   359
                // Decrementing the count of current worker threads.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   360
                // But, it will be increased in the finally block.
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   361
                decrementCurrentNumberOfThreads();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   362
                wrapper.workerThreadCreationFailure(t);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   363
            } finally {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   364
                incrementCurrentNumberOfThreads();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    public int minimumNumberOfThreads() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        return minWorkerThreads;
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    public int maximumNumberOfThreads() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
        return maxWorkerThreads;
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
    public long idleTimeoutForThreads() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        return inactivityTimeout;
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    public int currentNumberOfThreads() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   382
        synchronized (workQueue) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
            return currentThreadCount;
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   387
    void decrementCurrentNumberOfThreads() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   388
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   389
            currentThreadCount--;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   390
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   391
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   392
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   393
    void incrementCurrentNumberOfThreads() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   394
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   395
            currentThreadCount++;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   396
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   397
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   398
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
    public int numberOfAvailableThreads() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   400
        synchronized (workQueue) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
            return availableWorkerThreads;
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    public int numberOfBusyThreads() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   406
        synchronized (workQueue) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            return (currentThreadCount - availableWorkerThreads);
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
    public long averageWorkCompletionTime() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   412
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   413
            return (totalTimeTaken.get() / processedCount.get());
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
    public long currentProcessedCount() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   418
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   419
            return processedCount.get();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    public String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    * This method will return the number of WorkQueues serviced by the threadpool.
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
    public int numberOfWorkQueues() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
        return 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
    private static synchronized int getUniqueThreadId() {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   436
        return ThreadPoolImpl.threadCounter.incrementAndGet();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   437
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   438
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   439
    /**
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   440
     * This method will decrement the number of available threads
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   441
     * in the threadpool which are waiting for work. Called from
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   442
     * WorkQueueImpl.requestWork()
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   443
     */
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   444
    void decrementNumberOfAvailableThreads() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   445
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   446
            availableWorkerThreads--;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   447
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   448
    }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   449
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   450
    /**
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   451
     * This method will increment the number of available threads
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   452
     * in the threadpool which are waiting for work. Called from
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   453
     * WorkQueueImpl.requestWork()
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   454
     */
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   455
    void incrementNumberOfAvailableThreads() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   456
        synchronized (workQueue) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   457
            availableWorkerThreads++;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   458
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
33680
56aa0b79bf5a 8140606: Update library code to use internal Unsafe
chegar
parents: 29937
diff changeset
   462
    private class WorkerThread extends sun.misc.ManagedLocalsThread implements Closeable
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
        private Work currentWork;
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        private int threadId = 0; // unique id for the thread
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   466
        private volatile boolean closeCalled = false;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
        private String threadPoolName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        // name seen by Thread.getName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
        private StringBuffer workerThreadName = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        WorkerThread(ThreadGroup tg, String threadPoolName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            super(tg, "Idle");
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
            this.threadId = ThreadPoolImpl.getUniqueThreadId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            this.threadPoolName = threadPoolName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
            setName(composeWorkerThreadName(threadPoolName, "Idle"));
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   478
        public synchronized void close() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   479
            closeCalled = true;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   480
            interrupt();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   481
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   483
        private void resetClassLoader() {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   485
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   487
        private void performWork() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   488
            long start = System.currentTimeMillis();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   489
            try {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   490
                currentWork.doWork();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   491
            } catch (Throwable t) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   492
                wrapper.workerThreadDoWorkThrowable(this, t);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   493
            }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   494
            long elapsedTime = System.currentTimeMillis() - start;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   495
            totalTimeTaken.addAndGet(elapsedTime);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   496
            processedCount.incrementAndGet();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   497
        }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   499
        public void run() {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   500
            try  {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   501
                while (!closeCalled) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   502
                    try {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   503
                        currentWork = ((WorkQueueImpl)workQueue).requestWork(
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   504
                            inactivityTimeout);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   505
                        if (currentWork == null)
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   506
                            continue;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   507
                    } catch (InterruptedException exc) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   508
                        wrapper.workQueueThreadInterrupted( exc, getName(),
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   509
                           Boolean.valueOf(closeCalled));
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   511
                        continue ;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
                    } catch (Throwable t) {
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   513
                         wrapper.workerThreadThrowableFromRequestWork(this, t,
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   514
                                workQueue.getName());
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   515
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   516
                        continue;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   519
                    performWork();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                    // set currentWork to null so that the work item can be
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   522
                    // garbage collected without waiting for the next work item.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                    currentWork = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   525
                    resetClassLoader();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   526
                }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   527
            } catch (Throwable e) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   528
                // This should not be possible
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   529
                wrapper.workerThreadCaughtUnexpectedThrowable(this,e);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   530
            } finally {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   531
                synchronized (workersLock) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   532
                    workers.remove(this);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        private String composeWorkerThreadName(String poolName, String workerName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            workerThreadName.setLength(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            workerThreadName.append("p: ").append(poolName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
            workerThreadName.append("; w: ").append(workerName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
            return workerThreadName.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    } // End of WorkerThread class
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
// End of file.