-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
185 changed files
with
4,093 additions
and
62 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/org/kirito/multithreading/unit2/eg_2_1_1/HasSelfPrivateNum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_1; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class HasSelfPrivateNum { | ||
|
||
public void addI(String username) { | ||
try { | ||
int num = 0; | ||
if (username.equals("a")) { | ||
num = 100; | ||
System.out.println("a set over"); | ||
Thread.sleep(2000); | ||
} else { | ||
num = 200; | ||
System.out.println("b set over"); | ||
} | ||
System.out.println(username + " num=" + num); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/kirito/multithreading/unit2/eg_2_1_1/Run.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_1; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class Run { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
HasSelfPrivateNum numRef = new HasSelfPrivateNum(); | ||
ThreadA threadA = new ThreadA(numRef); | ||
threadA.start(); | ||
ThreadB threadB = new ThreadB(numRef); | ||
threadB.start(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_1/ThreadA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_1; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadA extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadA(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("a"); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_1/ThreadB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_1; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadB extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadB(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("b"); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/kirito/multithreading/unit2/eg_2_1_2/HasSelfPrivateNum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_2; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class HasSelfPrivateNum { | ||
private int num = 0; | ||
|
||
synchronized public void addI(String username) { | ||
try { | ||
if (username.equals("a")) { | ||
num = 100; | ||
System.out.println("a set over"); | ||
Thread.sleep(2000); | ||
} else { | ||
num = 200; | ||
System.out.println("b set over"); | ||
} | ||
System.out.println(username + " num=" + num); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/kirito/multithreading/unit2/eg_2_1_2/Run.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_2; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class Run { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
HasSelfPrivateNum numRef = new HasSelfPrivateNum(); | ||
ThreadA threadA = new ThreadA(numRef); | ||
threadA.start(); | ||
ThreadB threadB = new ThreadB(numRef); | ||
threadB.start(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_2/ThreadA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_2; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadA extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadA(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("a"); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_2/ThreadB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_2; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadB extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadB(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("b"); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/kirito/multithreading/unit2/eg_2_1_3/HasSelfPrivateNum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_3; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class HasSelfPrivateNum { | ||
private int num = 0; | ||
|
||
synchronized public void addI(String username) { | ||
try { | ||
if (username.equals("a")) { | ||
num = 100; | ||
System.out.println("a set over"); | ||
Thread.sleep(2000); | ||
} else { | ||
num = 200; | ||
System.out.println("b set over"); | ||
} | ||
System.out.println(username + " num=" + num); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/kirito/multithreading/unit2/eg_2_1_3/Run.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_3; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class Run { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
HasSelfPrivateNum numRef1 = new HasSelfPrivateNum(); | ||
HasSelfPrivateNum numRef2 = new HasSelfPrivateNum(); | ||
ThreadA threadA = new ThreadA(numRef1); | ||
threadA.start(); | ||
ThreadB threadB = new ThreadB(numRef2); | ||
threadB.start(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_3/ThreadA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_3; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadA extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadA(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("a"); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/kirito/multithreading/unit2/eg_2_1_3/ThreadB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kirito.multithreading.unit2.eg_2_1_3; | ||
|
||
/*** | ||
* Java Lib For MyProject, Powered By Kirito. | ||
* <p> | ||
* ----------------------------------------------------------------------------- | ||
* <p> | ||
* | ||
* @Description TODO(用一句话描述该文件做什么) | ||
* @Copyright Copyright (c) 2012-2016 | ||
* @version 1.0.0 | ||
* @author pangbo | ||
* @createDate 2016年11月7日 | ||
* @since JDK1.7 | ||
*/ | ||
public class ThreadB extends Thread { | ||
private HasSelfPrivateNum numRef; | ||
|
||
public ThreadB(HasSelfPrivateNum numRef) { | ||
super(); | ||
this.numRef = numRef; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
super.run(); | ||
numRef.addI("b"); | ||
} | ||
|
||
} |
Oops, something went wrong.