Skip to content

Commit f91fd4b

Browse files
committed
提交第九周作业
1 parent ad0fa06 commit f91fd4b

13 files changed

Lines changed: 170 additions & 9 deletions

File tree

03concurrency/0301/src/main/java/java0/conc0302/atomic/LongDemo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import java.util.concurrent.atomic.LongAdder;
55

66
public class LongDemo {
7-
7+
88
public static void main(String[] args) {
9-
9+
1010
final AtomicLong atomicLong = new AtomicLong();
1111
final LongAdder longAdder = new LongAdder();
12-
12+
1313
for (int i = 0; i < 100; i++) {
1414
new Thread(new Runnable() {
1515
@Override
@@ -21,15 +21,15 @@ public void run() {
2121
}
2222
}).start();
2323
}
24-
24+
2525
try {
2626
Thread.sleep(1000L);
2727
} catch (InterruptedException e) {
2828
e.printStackTrace();
2929
}
30-
30+
3131
System.out.println("atomicLong=" + atomicLong.get());
3232
System.out.println("longAdder =" + longAdder.sum());
33-
33+
3434
}
3535
}

03concurrency/0301/src/main/java/java0/conc0302/atomic/SyncCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class SyncCount {
88

9-
private int num = 0;
9+
private volatile int num = 0;
1010

1111
private Lock lock = new ReentrantLock(true);
1212

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.kimmking.homework.aop;
2+
3+
/**
4+
* @author cpx
5+
* @Description
6+
* @date 2022/7/31
7+
*/
8+
public class ISchool implements School{
9+
@Override
10+
public void start() {
11+
System.out.println("开始上课了");
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.kimmking.homework.aop;
2+
3+
public interface School {
4+
void start();
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.kimmking.homework.aop;
2+
3+
import java.lang.reflect.InvocationHandler;
4+
import java.lang.reflect.Method;
5+
6+
/**
7+
* @author cpx
8+
* @Description
9+
* @date 2022/7/31
10+
*/
11+
public class SchoolProxy implements InvocationHandler {
12+
private Object bean;
13+
14+
public SchoolProxy(Object bean) {
15+
this.bean = bean;
16+
}
17+
18+
@Override
19+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
20+
String methodName = method.getName();
21+
if (methodName.equals("start")) {
22+
System.out.println("上课铃声响了");
23+
} else {
24+
System.out.println("下课铃声响了");
25+
}
26+
return method.invoke(bean, args);
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.kimmking.homework.aop;
2+
3+
import java.lang.reflect.Proxy;
4+
5+
/**
6+
* @author cpx
7+
* @Description
8+
* @date 2022/7/31
9+
*/
10+
public class TestDemo {
11+
public static void main(String[] args) {
12+
SchoolProxy schoolProxy = new SchoolProxy(new ISchool());
13+
School school = (School) Proxy.newProxyInstance(schoolProxy.getClass().getClassLoader(), new Class[]{School.class},schoolProxy);
14+
school.start();
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
使用JAVA的动态代理实现一个简单的AOP
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.kimmking.homework.instancebean;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.stereotype.Service;
5+
6+
/**
7+
* @author cpx
8+
* @Description
9+
* @date 2022/7/31
10+
*/
11+
@Service
12+
public class AnnotationBean {
13+
@Bean
14+
public Teacher generateTeacher() {
15+
return new Teacher(20,"程鹏祥");
16+
}
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.kimmking.homework.instancebean;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
6+
/**
7+
* @author cpx
8+
* @Description
9+
* @date 2022/7/31
10+
*/
11+
public class Teacher {
12+
private int age;
13+
private String name;
14+
15+
public Teacher(int age, String name) {
16+
this.age = age;
17+
this.name = name;
18+
}
19+
20+
public Teacher() {
21+
22+
}
23+
24+
public int getAge() {
25+
return age;
26+
}
27+
28+
public void setAge(int age) {
29+
this.age = age;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.kimmking.homework.instancebean;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
import java.util.Arrays;
7+
8+
/**
9+
* @author cpx
10+
* @Description
11+
* @date 2022/7/31
12+
*/
13+
public class TestHomeWork {
14+
public static void main(String[] args) {
15+
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContextcpx.xml");
16+
String[] names = context.getBeanDefinitionNames();
17+
for (String name : names) {
18+
System.out.println(">>>>>" + name);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)