File tree Expand file tree Collapse file tree 2 files changed +3
-2
lines changed
03concurrency/0301/src/main/java/java0/conc0303 Expand file tree Collapse file tree 2 files changed +3
-2
lines changed Original file line number Diff line number Diff line change 33import java .util .concurrent .CopyOnWriteArrayList ;
44
55public class CopyOnWriteArrayListDemo2 {
6-
6+ // 并不能证明线程不安全
77 private final static CopyOnWriteArrayList <String > list = new CopyOnWriteArrayList ();
88
99 public static void main (String [] args ) {
@@ -22,7 +22,7 @@ public static void test(){
2222 @ Override
2323 public void run () {
2424 while (true ) {
25- if (list .size () > 0 ) { // todo : 下一个get操作执行时,size可能已经是0了
25+ if (list .size () > 0 ) { // 下一个get操作执行时,size可能已经是0了
2626 String content = list .get (list .size () - 1 );
2727 }else {
2828 break ;
Original file line number Diff line number Diff line change 11package java0 .conc0303 .threadlocal ;
22
3+ // 框架使用,隐式传参,多个方法之间不用一直传
34public class ThreadLocalDemo {
45
56 private static ThreadLocal <Integer > seqNum = new ThreadLocal <Integer >() {
You can’t perform that action at this time.
0 commit comments