ThreadGroup
Thread Group Hierarchy
Volatility
http://www.javamex.com/tutorials/synchronization_volatile.shtml
http://www.javamex.com/tutorials/synchronization_volatile_when.shtml
ThreadLocal
ThreadLocal从JDK1.2开始就存在了,它提供了三个方法:
1) Object get()
2) Object initialValue():默认return null,需要继承ThreadLocal然后Override返回不同的值
3) void setValue(Object value)
class MyThread extends Thread {
private final ThreadLocal<Integer> tl;
public MyThread(ThreadLocal<Integer> tl) {
this.tl = tl;
}
@Override
public void run() {
for (int i = 0; i < 10; i++) {
tl.set(tl.get() + 1);
System.out.println(Thread.currentThread().toString() + tl.get());
}
}
}
如果启动两个MyThread的实例,然后start,可以看到输出的结果是相互不影响的,因为每个Thread都有其自己单独的ThreadLocal的值。InheritableThreadLocal
Timer & TimerTask
从JDK1.3开始,有了Timer和TimerTask。Timer是用来执行TimerTask的。
创建Timer:
Timer nonDaemonTimer = new Timer();
Timer daemonTimer = new Timer(true);
创建TimerTask:
class MyTask extends TimerTask
{
public void run ()
{
System.out.println ("MyTask task is running.");
}
}
使用Timer调度TimerTask:
void schedule(TimerTask ....),可配置delay,interval,Date等
ThreadDeath对象
参考资料:
http://www.javaworld.com/article/2074481/java-concurrency/java-101--understanding-java-threads--part-4---thread-groups--volatility--and-threa.html