Skip to content

Commit

Permalink
concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
landy committed Feb 28, 2019
1 parent ba07379 commit 2ae7002
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
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);
}
}
23 changes: 23 additions & 0 deletions learn-springel/src/test/java/depTest/ClassA.java
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...");
}
}
23 changes: 23 additions & 0 deletions learn-springel/src/test/java/depTest/ClassB.java
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");
}
}
17 changes: 17 additions & 0 deletions learn-springel/src/test/java/depTest/DepTest.java
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");

}
}
12 changes: 12 additions & 0 deletions learn-springel/src/test/resources/test1.xml
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>

0 comments on commit 2ae7002

Please sign in to comment.