2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.util
;
20 import java
.lang
.Thread
.UncaughtExceptionHandler
;
22 import org
.apache
.yetus
.audience
.InterfaceAudience
;
25 * Abstract class which contains a Thread and delegates the common Thread
26 * methods to that instance.
28 * The purpose of this class is to workaround Sun JVM bug #6915621, in which
29 * something internal to the JDK uses Thread.currentThread() as a monitor
30 * lock. This can produce deadlocks like HBASE-4367, HBASE-4101, etc.
32 @InterfaceAudience.Private
33 public abstract class HasThread
implements Runnable
{
34 private final Thread thread
;
37 this.thread
= new Thread(this);
38 this.thread
.setDaemon(true);
41 public HasThread(String name
) {
42 this.thread
= new Thread(this, name
);
43 this.thread
.setDaemon(true);
46 public Thread
getThread() {
51 public abstract void run();
53 //// Begin delegation to Thread
55 public final String
getName() {
56 return thread
.getName();
59 public void interrupt() {
63 public final boolean isAlive() {
64 return thread
.isAlive();
67 public boolean isInterrupted() {
68 return thread
.isInterrupted();
71 public final void setDaemon(boolean on
) {
75 public final void setName(String name
) {
79 public final void setPriority(int newPriority
) {
80 thread
.setPriority(newPriority
);
83 public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh
) {
84 thread
.setUncaughtExceptionHandler(eh
);
91 public final void join() throws InterruptedException
{
95 public final void join(long millis
, int nanos
) throws InterruptedException
{
96 thread
.join(millis
, nanos
);
99 public final void join(long millis
) throws InterruptedException
{
102 //// End delegation to Thread