JUC Thread(TODO)

———— JDK 1.8
words: 287    views:    time: 1min

这里整理需要涉及一些C++源码,待后续进行梳理

1. 属性

java.lang.Thread
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
private volatile String name; // 线程名字

private int priority; // 线程优先级

private Thread threadQ;

private long eetop;

private boolean single_step;

private boolean daemon = false; // 是否守护线程

private boolean stillborn = false;

private Runnable target; // 待执行的任务

private ThreadGroup group; // 所属线程组

private ClassLoader contextClassLoader;

private AccessControlContext inheritedAccessControlContext;

ThreadLocal.ThreadLocalMap threadLocals = null;

ThreadLocal.ThreadLocalMap inheritableThreadLocals = null;

private long stackSize;

private long nativeParkEventPointer;

private long tid; // 线程id

private volatile int threadStatus = 0; // 线程状态

volatile Object parkBlocker;

private volatile Interruptible blocker;

private final Object blockerLock = new Object();

private static int threadInitNumber;

private static long threadSeqNumber;

1.1. threadStatus 状态

java.lang.Thread
1
2
3
public enum State {
NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED;
}

2. native

java.lang.Thread
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static {
registerNatives();
}

private static native void registerNatives();

private static native StackTraceElement[][] dumpThreads(Thread[] threads);

private static native Thread[] getThreads();

public static native Thread currentThread();

public static native void yield();

public static native void sleep(long millis) throws InterruptedException;

public static native boolean holdsLock(Object obj);

public final native boolean isAlive();

private native void start0();

private native boolean isInterrupted(boolean ClearInterrupted);

private native void setPriority0(int newPriority);

private native void stop0(Object o);

private native void suspend0();

private native void resume0();

private native void interrupt0();

private native void setNativeName(String name);

3. 接口

3.1. start

3.2. interrupt

3.3. sleep

3.4. yield

3.5. join


参考:

  1. https://cloud.tencent.com/developer/article/1773799?from=article.detail.1773798
  2. https://cloud.tencent.com/developer/article/1697203?from=article.detail.1773799