File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
src/main/java/io/github/dunwu/javase/container/base Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <project xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3
+ xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
4
+ <modelVersion >4.0.0</modelVersion >
5
+
6
+ <parent >
7
+ <groupId >io.github.dunwu</groupId >
8
+ <artifactId >javase-notes</artifactId >
9
+ <version >1.0.1</version >
10
+ </parent >
11
+ <artifactId >javase-container</artifactId >
12
+ <packaging >jar</packaging >
13
+ <name >${project.artifactId} </name >
14
+ <description >Java容器示例</description >
15
+
16
+ </project >
Original file line number Diff line number Diff line change
1
+ package io .github .dunwu .javase .container .base ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .Iterator ;
5
+ import java .util .List ;
6
+
7
+ /**
8
+ * Java 容器 fail-fast 机制示例
9
+ * @author Zhang Peng
10
+ * @date 2018/6/29
11
+ */
12
+ public class FailFastDemo {
13
+ private static List <Integer > list = new ArrayList <>();
14
+
15
+ private static class ThreadOne extends Thread {
16
+ public void run () {
17
+ Iterator <Integer > iterator = list .iterator ();
18
+ while (iterator .hasNext ()) {
19
+ int i = iterator .next ();
20
+ System .out .println ("ThreadOne 遍历:" + i );
21
+ try {
22
+ Thread .sleep (10 );
23
+ } catch (InterruptedException e ) {
24
+ e .printStackTrace ();
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ private static class ThreadTwo extends Thread {
31
+ public void run () {
32
+ int i = 0 ;
33
+ while (i < 6 ) {
34
+ System .out .println ("ThreadTwo run:" + i );
35
+ if (i == 3 ) {
36
+ list .remove (i );
37
+ }
38
+ i ++;
39
+ }
40
+ }
41
+ }
42
+
43
+ public static void main (String [] args ) {
44
+ for (int i = 0 ; i < 100 ; i ++) {
45
+ list .add (i );
46
+ }
47
+ new ThreadOne ().start ();
48
+ new ThreadTwo ().start ();
49
+ }
50
+ }
Original file line number Diff line number Diff line change 21
21
<module >effective</module >
22
22
<module >jdk8</module >
23
23
<module >jvm</module >
24
+ <module >container</module >
24
25
<module >concurrent</module >
25
26
<module >util</module >
26
27
<module >oop</module >
You can’t perform that action at this time.
0 commit comments