| 集合类型 | 非线程安全 | 线程安全 |
| List | ArrayList | CopyOnWriteArrayList |
| Set | SortedSet | ConcurrentSkipListSet |
| Map | HashMap、SortedMap | ConcurrentHashMap、ConcurrentSkipListMap、 |
// 第一种方式
Thread thread = new Thread("interrupt test") {
public void run() {
for (;;) {
doXXX();
if (Thread.interrupted()) {
break;
}
}
}
};
thread.start();
// 第二种方式
Thread thread = new Thread("interrupt test") {
public void run() {
for (;;) {
try {
doXXX();
} catch (InterruptedException e) {
break;
} catch (Exception e) {
// handle Exception
}
}
}
};
thread.start();
// 第三种方式
public void foo() throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException();
}
}《Java并发编程实战》第五章 同步容器类 读书笔记,布布扣,bubuko.com
原文:http://blog.csdn.net/androiddevelop/article/details/26928821