Skip to content

Commit 647cc63

Browse files
committed
add some test codes
1 parent 8b854ed commit 647cc63

File tree

14 files changed

+324
-8
lines changed

14 files changed

+324
-8
lines changed

03concurrency/0301/j.txt

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2022-06-09 15:15:13
2+
Full thread dump OpenJDK 64-Bit Server VM (25.275-b00 mixed mode):
3+
4+
"Attach Listener" #12 daemon prio=9 os_prio=31 tid=0x00007f90df895000 nid=0xa703 waiting on condition [0x0000000000000000]
5+
java.lang.Thread.State: RUNNABLE
6+
7+
Locked ownable synchronizers:
8+
- None
9+
10+
"Thread-0" #11 prio=5 os_prio=31 tid=0x00007f90e105d800 nid=0x5603 waiting for monitor entry [0x0000700005164000]
11+
java.lang.Thread.State: BLOCKED (on object monitor)
12+
at java0.conc0301.sync.TestSetGet$SetGet.get(TestSetGet.java:50)
13+
- waiting to lock <0x000000076ac2ed68> (a java0.conc0301.sync.TestSetGet$SetGet)
14+
at java0.conc0301.sync.TestSetGet$1.run(TestSetGet.java:14)
15+
16+
Locked ownable synchronizers:
17+
- None
18+
19+
"Service Thread" #10 daemon prio=9 os_prio=31 tid=0x00007f90e1051800 nid=0x3d03 runnable [0x0000000000000000]
20+
java.lang.Thread.State: RUNNABLE
21+
22+
Locked ownable synchronizers:
23+
- None
24+
25+
"C1 CompilerThread3" #9 daemon prio=9 os_prio=31 tid=0x00007f90e4808800 nid=0x3c03 waiting on condition [0x0000000000000000]
26+
java.lang.Thread.State: RUNNABLE
27+
28+
Locked ownable synchronizers:
29+
- None
30+
31+
"C2 CompilerThread2" #8 daemon prio=9 os_prio=31 tid=0x00007f90e1026000 nid=0x3b03 waiting on condition [0x0000000000000000]
32+
java.lang.Thread.State: RUNNABLE
33+
34+
Locked ownable synchronizers:
35+
- None
36+
37+
"C2 CompilerThread1" #7 daemon prio=9 os_prio=31 tid=0x00007f90df872000 nid=0x3903 waiting on condition [0x0000000000000000]
38+
java.lang.Thread.State: RUNNABLE
39+
40+
Locked ownable synchronizers:
41+
- None
42+
43+
"C2 CompilerThread0" #6 daemon prio=9 os_prio=31 tid=0x00007f90df871000 nid=0x3803 waiting on condition [0x0000000000000000]
44+
java.lang.Thread.State: RUNNABLE
45+
46+
Locked ownable synchronizers:
47+
- None
48+
49+
"Monitor Ctrl-Break" #5 daemon prio=5 os_prio=31 tid=0x00007f90df86d800 nid=0x4203 runnable [0x0000700004a4f000]
50+
java.lang.Thread.State: RUNNABLE
51+
at java.net.SocketInputStream.socketRead0(Native Method)
52+
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
53+
at java.net.SocketInputStream.read(SocketInputStream.java:171)
54+
at java.net.SocketInputStream.read(SocketInputStream.java:141)
55+
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
56+
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
57+
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
58+
- locked <0x000000076ac7c0d0> (a java.io.InputStreamReader)
59+
at java.io.InputStreamReader.read(InputStreamReader.java:184)
60+
at java.io.BufferedReader.fill(BufferedReader.java:161)
61+
at java.io.BufferedReader.readLine(BufferedReader.java:324)
62+
- locked <0x000000076ac7c0d0> (a java.io.InputStreamReader)
63+
at java.io.BufferedReader.readLine(BufferedReader.java:389)
64+
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:49)
65+
66+
Locked ownable synchronizers:
67+
- None
68+
69+
"Signal Dispatcher" #4 daemon prio=9 os_prio=31 tid=0x00007f90e3808800 nid=0x4403 runnable [0x0000000000000000]
70+
java.lang.Thread.State: RUNNABLE
71+
72+
Locked ownable synchronizers:
73+
- None
74+
75+
"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007f90df056800 nid=0x4d03 in Object.wait() [0x0000700004743000]
76+
java.lang.Thread.State: WAITING (on object monitor)
77+
at java.lang.Object.wait(Native Method)
78+
- waiting on <0x000000076ab08ee0> (a java.lang.ref.ReferenceQueue$Lock)
79+
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
80+
- locked <0x000000076ab08ee0> (a java.lang.ref.ReferenceQueue$Lock)
81+
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
82+
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
83+
84+
Locked ownable synchronizers:
85+
- None
86+
87+
"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007f90df04e000 nid=0x3303 in Object.wait() [0x0000700004640000]
88+
java.lang.Thread.State: WAITING (on object monitor)
89+
at java.lang.Object.wait(Native Method)
90+
- waiting on <0x000000076ab06c00> (a java.lang.ref.Reference$Lock)
91+
at java.lang.Object.wait(Object.java:502)
92+
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
93+
- locked <0x000000076ab06c00> (a java.lang.ref.Reference$Lock)
94+
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
95+
96+
Locked ownable synchronizers:
97+
- None
98+
99+
"main" #1 prio=5 os_prio=31 tid=0x00007f90df009000 nid=0x2803 waiting on condition [0x0000700003c22000]
100+
java.lang.Thread.State: TIMED_WAITING (sleeping)
101+
at java.lang.Thread.sleep(Native Method)
102+
at java0.conc0301.sync.TestSetGet$SetGet.set(TestSetGet.java:37)
103+
- locked <0x000000076ac2ed68> (a java0.conc0301.sync.TestSetGet$SetGet)
104+
at java0.conc0301.sync.TestSetGet.main(TestSetGet.java:22)
105+
106+
Locked ownable synchronizers:
107+
- None
108+
109+
"VM Thread" os_prio=31 tid=0x00007f90df81c000 nid=0x4f03 runnable
110+
111+
"GC task thread#0 (ParallelGC)" os_prio=31 tid=0x00007f90df016000 nid=0x1d07 runnable
112+
113+
"GC task thread#1 (ParallelGC)" os_prio=31 tid=0x00007f90df016800 nid=0x1e03 runnable
114+
115+
"GC task thread#2 (ParallelGC)" os_prio=31 tid=0x00007f90df017800 nid=0x2b03 runnable
116+
117+
"GC task thread#3 (ParallelGC)" os_prio=31 tid=0x00007f90df018000 nid=0x2d03 runnable
118+
119+
"GC task thread#4 (ParallelGC)" os_prio=31 tid=0x00007f90df019000 nid=0x2f03 runnable
120+
121+
"GC task thread#5 (ParallelGC)" os_prio=31 tid=0x00007f90df019800 nid=0x5303 runnable
122+
123+
"GC task thread#6 (ParallelGC)" os_prio=31 tid=0x00007f90df01a800 nid=0x3003 runnable
124+
125+
"GC task thread#7 (ParallelGC)" os_prio=31 tid=0x00007f90df01b000 nid=0x3103 runnable
126+
127+
"VM Periodic Task Thread" os_prio=31 tid=0x00007f90e105a800 nid=0xa903 waiting on condition
128+
129+
JNI global references: 15
130+

03concurrency/0301/src/main/java/java0/conc0301/sync/TestSetGet.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package java0.conc0301.sync;
22

3+
import java.lang.reflect.Field;
4+
35
public class TestSetGet {
46

57
public static void main(String[] args) throws Exception {
@@ -22,20 +24,29 @@ public void run() {
2224

2325
}
2426

25-
2627
public static class SetGet {
2728

2829
int a = 0;
2930
public synchronized void set(int v) throws Exception {
31+
System.out.println(addr(Thread.currentThread()));
32+
System.out.println(Thread.currentThread().getId());
3033
System.out.println(Thread.currentThread().getName() +" setting " +v);
31-
Thread.sleep(1000);
34+
Thread.sleep(100000);
3235
a = v;
3336
System.out.println(Thread.currentThread().getName() +" set " +v);
3437
}
3538

39+
private Object addr(Thread currentThread) throws Exception {
40+
Field f = Thread.class.getDeclaredField("eetop");
41+
f.setAccessible(true);
42+
Long addr = (Long)f.get(currentThread);
43+
return Long.toHexString(addr);
44+
}
45+
3646
public synchronized int get() throws Exception {
47+
System.out.println(Thread.currentThread().getId());
3748
System.out.println(Thread.currentThread().getName() +" getting ");
38-
Thread.sleep(10000);
49+
Thread.sleep(100000);
3950
System.out.println(Thread.currentThread().getName() + " get ");
4051
return a;
4152
}

04fx/spring01/src/main/java/io/kimmking/anno/AnnoDemo.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
package io.kimmking.anno;
22

3+
import java.lang.annotation.Annotation;
4+
import java.util.Arrays;
5+
36
public class AnnoDemo {
47

58
public static void main(String[] args) {
9+
IA2 ia2 = new IA2() {
10+
@Override
11+
public void a2() {
12+
System.out.println("a2.");
13+
}
14+
15+
@Override
16+
public void a1() {
17+
System.out.println("a1.");
18+
}
19+
};
20+
21+
Annotation[] annotations = ia2.getClass().getInterfaces()[0].getAnnotations();
22+
Arrays.stream(annotations).forEach(x -> System.out.println(x.annotationType().getCanonicalName()));
23+
24+
Annotation[] annos2 = ia2.getClass().getInterfaces()[0].getInterfaces()[0].getAnnotations();
25+
Arrays.stream(annos2).forEach(x -> System.out.println(x.annotationType().getCanonicalName()));
26+
Arrays.stream(annos2).forEach(
27+
x -> {
28+
IAnno2 anno2 = (IAnno2) x;
29+
System.out.println(anno2.value());
30+
});
631

732
}
833

04fx/spring01/src/main/java/io/kimmking/anno/IA1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.kimmking.anno;
22

33

4+
@IAnno2("anno2")
45
public interface IA1 {
56

67
void a1();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.kimmking.anno;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target({ElementType.TYPE})
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface IAnno2 {
11+
12+
String value();
13+
14+
}

04fx/spring01/src/main/java/io/kimmking/spring02/School.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import io.kimmking.spring01.Student;
55
import lombok.Data;
66
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.context.annotation.Bean;
78

9+
import javax.annotation.PostConstruct;
810
import javax.annotation.Resource;
911

1012
@Data
@@ -23,5 +25,6 @@ public void ding(){
2325
System.out.println("Class1 have " + this.class1.getStudents().size() + " students and one is " + this.student100);
2426

2527
}
28+
2629

2730
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.kimmking.spring03;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
6+
public class Spring03Main {
7+
8+
public static void main(String[] args) {
9+
ApplicationContext context = new AnnotationConfigApplicationContext(Spring03Main.class.getPackage().getName());
10+
TestService1 testService1 = context.getBean(TestService1.class);
11+
testService1.test1();
12+
}
13+
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.kimmking.spring03;
2+
3+
import lombok.Data;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.scheduling.annotation.Async;
6+
import org.springframework.scheduling.annotation.EnableAsync;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
@Data
11+
@EnableAsync
12+
public class TestService1 { // TODO rename this class to TestService6 and it works well.
13+
14+
@Autowired
15+
private TestService2 service2;
16+
17+
@Async
18+
public void test1() {
19+
System.out.println("test1");
20+
System.out.println(this.getClass().getCanonicalName());
21+
System.out.println(Thread.currentThread().getName());
22+
}
23+
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.kimmking.spring03;
2+
3+
import lombok.Data;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
@Data
9+
public class TestService2 {
10+
11+
@Autowired
12+
private TestService1 service1;
13+
14+
public void test2() {
15+
System.out.println("test2");
16+
}
17+
18+
}

04fx/spring01/src/main/java/io/kimmking/springjms/JmsSender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public static void main( String[] args )
1313
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:springjms-sender.xml");
1414

1515
SendService sendService = (SendService)context.getBean("sendService");
16-
16+
17+
student2.setName("KK103");
18+
1719
sendService.send(student2);
1820

1921
System.out.println("send successfully, please visit http://localhost:8161/admin to see it");

08cache/cache/src/main/resources/application.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ spring:
1010
cache:
1111
type: redis
1212
redis:
13-
host: localhost
13+
timeout: 3000ms
14+
database: 0
15+
cluster:
16+
nodes:
17+
- 127.0.0.1:7000
18+
- 127.0.0.1:7001
19+
- 127.0.0.1:7002
20+
- 127.0.0.1:7003
21+
- 127.0.0.1:7004
22+
- 127.0.0.1:7005
23+
max-redirects: 3 # 获取失败 最大重定向次数
1424
lettuce:
1525
pool:
16-
max-active: 16
17-
max-wait: 10ms
26+
max-active: 1000 #连接池最大连接数(使用负值表示没有限制)
27+
max-idle: 10 # 连接池中的最大空闲连接
28+
min-idle: 5 # 连接池中的最小空闲连接
29+
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
1830

1931
# type: ehcache
2032
# ehcache:

08cache/cache/test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CREATE TABLE `user` (
3636

3737
LOCK TABLES `user` WRITE;
3838
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
39-
INSERT INTO `user` VALUES (1,'KK',20),(2,'CC',18),(3,'MK',21);
39+
INSERT INTO `user` VALUES (1,'K1',21),(2,'K2',22),(3,'K3',23),(4,'K4',24),(5,'K5',25),(6,'K6',26);
4040
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
4141
UNLOCK TABLES;
4242
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

0 commit comments

Comments
 (0)