-
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
landy
committed
Feb 28, 2019
1 parent
ba07379
commit 2ae7002
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
learn-concurrency/src/test/java/com/github/landyking/learnConcurrency/CyclicBarrierTest.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,40 @@ | ||
package com.github.landyking.learnConcurrency; | ||
|
||
import java.util.concurrent.BrokenBarrierException; | ||
import java.util.concurrent.CyclicBarrier; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created by landy on 2019/2/28. | ||
*/ | ||
public class CyclicBarrierTest { | ||
public static void main(String[] args) throws InterruptedException, BrokenBarrierException { | ||
final CyclicBarrier barrier = new CyclicBarrier(4, new Runnable() { | ||
@Override | ||
public void run() { | ||
System.out.println(Thread.currentThread().getName() + " # barrier action"); | ||
} | ||
}); | ||
for (int i = 0; i < 4; i++) { | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
for (int j = 0; j < 2; j++) { | ||
|
||
try { | ||
System.out.println(Thread.currentThread().getName() + "-" + j + " ##### start"); | ||
int await = barrier.await(); | ||
System.out.println(Thread.currentThread().getName() + "-" + j + " ##### over "+await); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} catch (BrokenBarrierException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}).start(); | ||
} | ||
System.out.println("############"); | ||
TimeUnit.SECONDS.sleep(100); | ||
} | ||
} |
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,23 @@ | ||
package depTest; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
/** | ||
* Created by landy on 2018/12/15. | ||
*/ | ||
public class ClassA implements InitializingBean{ | ||
private ClassB b; | ||
|
||
public ClassB getB() { | ||
return b; | ||
} | ||
|
||
public void setB(ClassB b) { | ||
this.b = b; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
System.out.println("init a..."); | ||
} | ||
} |
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,23 @@ | ||
package depTest; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
/** | ||
* Created by landy on 2018/12/15. | ||
*/ | ||
public class ClassB implements InitializingBean{ | ||
private ClassA a; | ||
|
||
public ClassA getA() { | ||
return a; | ||
} | ||
|
||
public void setA(ClassA a) { | ||
this.a = a; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
System.out.println("init b"); | ||
} | ||
} |
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,17 @@ | ||
package depTest; | ||
|
||
import org.junit.Test; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
/** | ||
* Created by landy on 2018/12/15. | ||
*/ | ||
public class DepTest { | ||
@Test | ||
public void test() throws Exception { | ||
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("test1.xml"); | ||
// Object a = app.getBean("a"); | ||
Object b = app.getBean("b"); | ||
|
||
} | ||
} |
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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http:https://www.springframework.org/schema/beans" | ||
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http:https://www.springframework.org/schema/beans http:https://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="a" class="depTest.ClassA" lazy-init="true"> | ||
<property name="b" ref="b"/> | ||
</bean> | ||
<bean id="b" class="depTest.ClassB" lazy-init="true"> | ||
<property name="a" ref="a"/> | ||
</bean> | ||
</beans> |