File tree Expand file tree Collapse file tree 3 files changed +8
-12
lines changed
gRPC-Demo/src/main/java/cn/mrdear/grpc/hellopool Expand file tree Collapse file tree 3 files changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public class HelloWorldClientPool {
37
37
/**
38
38
* 从连接池获取对象
39
39
*/
40
- public static HelloWorldClientSingle borrowObject (){
40
+ private static HelloWorldClientSingle borrowObject (){
41
41
try {
42
42
HelloWorldClientSingle clientSingle = objectPool .borrowObject ();
43
43
System .out .println ("总创建线程数" +objectPool .getCreatedCount ());
@@ -49,13 +49,6 @@ public static HelloWorldClientSingle borrowObject(){
49
49
return createClient ();
50
50
}
51
51
52
- /**
53
- * 还送对象
54
- */
55
- public static void returnObject (HelloWorldClientSingle clientSingle ){
56
- objectPool .returnObject (clientSingle );
57
- }
58
-
59
52
/**
60
53
* 当连接池异常,则主动创建对象
61
54
*/
@@ -74,7 +67,7 @@ public static Runnable execute(WorkCallBack<HelloWorldClientSingle> workCallBack
74
67
workCallBack .callback (client );
75
68
} finally {
76
69
/** 将连接对象返回给连接池 */
77
- returnObject (client );
70
+ objectPool . returnObject (client );
78
71
}
79
72
};
80
73
}
Original file line number Diff line number Diff line change @@ -13,7 +13,4 @@ public static void main(String[] args) {
13
13
})).start ();
14
14
}
15
15
}
16
-
17
-
18
-
19
16
}
Original file line number Diff line number Diff line change @@ -24,4 +24,10 @@ public HelloWorldClientSingle create() throws Exception {
24
24
public PooledObject <HelloWorldClientSingle > wrap (HelloWorldClientSingle helloWorldClientSingle ) {
25
25
return new DefaultPooledObject <>(helloWorldClientSingle );
26
26
}
27
+
28
+ @ Override
29
+ public void destroyObject (PooledObject <HelloWorldClientSingle > p ) throws Exception {
30
+ p .getObject ().shutdown ();
31
+ super .destroyObject (p );
32
+ }
27
33
}
You can’t perform that action at this time.
0 commit comments