質問編集履歴
1
文言の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
外部へのhttps通信処理をspring bootで実装しています。
|
2
2
|
|
3
3
|
通知先が多いと送信処理に時間がかかってしまう為、マルチスレッドを使って処理時間を減らそうと思います。
|
4
4
|
|
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
・画面から配信データを入力、送信ボタンを押す
|
10
10
|
|
11
|
-
・DBから通知先
|
11
|
+
・DBから通知先データのリストを取得
|
12
12
|
|
13
|
-
・
|
13
|
+
・通知先データの数だけ送信処理を繰り返す(ここでマルチスレッドを実装)
|
14
14
|
|
15
15
|
・送信処理を行った件数を画面に出力する
|
16
16
|
|
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
■
|
29
|
+
■DemoApplication.class
|
30
30
|
|
31
31
|
```ここに言語を入力
|
32
32
|
|
@@ -34,13 +34,13 @@
|
|
34
34
|
|
35
35
|
@EnableAsync
|
36
36
|
|
37
|
-
public class
|
37
|
+
public class DemoApplication {
|
38
38
|
|
39
39
|
|
40
40
|
|
41
41
|
public static void main(String[] args) {
|
42
42
|
|
43
|
-
SpringApplication.run(
|
43
|
+
SpringApplication.run(DemoApplication .class, args);
|
44
44
|
|
45
45
|
}
|
46
46
|
|
@@ -50,17 +50,17 @@
|
|
50
50
|
|
51
51
|
```
|
52
52
|
|
53
|
-
|
53
|
+
|
54
54
|
|
55
55
|
```ここに言語を入力
|
56
56
|
|
57
57
|
@Controller
|
58
58
|
|
59
|
-
public class
|
59
|
+
public class DemoController {
|
60
60
|
|
61
61
|
@Autowired
|
62
62
|
|
63
|
-
|
63
|
+
DemoService service;
|
64
64
|
|
65
65
|
|
66
66
|
|
@@ -72,19 +72,17 @@
|
|
72
72
|
|
73
73
|
public String subscribe(@ModelAttribute SendForm form, RedirectAttributes redirectAttribute) {
|
74
74
|
|
75
|
-
//エンドポイントリストを取得
|
76
|
-
|
77
|
-
List<
|
75
|
+
List<DemoData> list = this.service.getTargetList();
|
78
76
|
|
79
77
|
int num = list.size();
|
80
78
|
|
81
79
|
|
82
80
|
|
83
|
-
this.service.send
|
81
|
+
this.service.send(list, form);
|
84
82
|
|
85
83
|
|
86
84
|
|
87
|
-
redirectAttribute.addFlashAttribute("
|
85
|
+
redirectAttribute.addFlashAttribute("num", num);
|
88
86
|
|
89
87
|
return "redirect:/";
|
90
88
|
|
@@ -100,15 +98,15 @@
|
|
100
98
|
|
101
99
|
@Service
|
102
100
|
|
103
|
-
public class
|
101
|
+
public class DemoService {
|
104
102
|
|
105
103
|
@Autowired
|
106
104
|
|
107
|
-
|
105
|
+
DemoConfiguration config;
|
108
106
|
|
109
107
|
|
110
108
|
|
111
|
-
private static final Log log = LogFactory.getLog(
|
109
|
+
private static final Log log = LogFactory.getLog(DemoService.class);
|
112
110
|
|
113
111
|
|
114
112
|
|
@@ -116,11 +114,7 @@
|
|
116
114
|
|
117
115
|
|
118
116
|
|
119
|
-
public void send
|
117
|
+
public void send(List<DemoData> list, SendForm form) {
|
120
|
-
|
121
|
-
Security.addProvider(new BouncyCastleProvider());
|
122
|
-
|
123
|
-
|
124
118
|
|
125
119
|
final String PUBLIC_KEY = this.config.getPublicKey();
|
126
120
|
|
@@ -138,11 +132,11 @@
|
|
138
132
|
|
139
133
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
140
134
|
|
141
|
-
|
135
|
+
DemoService demoService = null;
|
142
136
|
|
143
137
|
try {
|
144
138
|
|
145
|
-
|
139
|
+
demoService = new DemoService(PUBLIC_KEY, PRIVATE_KEY, SUBJECT);
|
146
140
|
|
147
141
|
payload = mapper.writeValueAsString(form);
|
148
142
|
|
@@ -158,7 +152,7 @@
|
|
158
152
|
|
159
153
|
String subscriptionJson = list.get(i).getJson();
|
160
154
|
|
161
|
-
this.asyncSend
|
155
|
+
this.asyncSend(i,subscriptionJson, mapper, payload, demoService);
|
162
156
|
|
163
157
|
}
|
164
158
|
|
@@ -170,11 +164,7 @@
|
|
170
164
|
|
171
165
|
@Async
|
172
166
|
|
173
|
-
private void asyncSend
|
167
|
+
private void asyncSend(int i, String subscriptionJson, ObjectMapper mapper, String payload, DemoService demoService) {
|
174
|
-
|
175
|
-
log.info("service start." + i);
|
176
|
-
|
177
|
-
int statusCode = 0;
|
178
168
|
|
179
169
|
try {
|
180
170
|
|
@@ -182,7 +172,7 @@
|
|
182
172
|
|
183
173
|
Notification notification = new Notification(subscription, payload);
|
184
174
|
|
185
|
-
|
175
|
+
demoService.send(notification);
|
186
176
|
|
187
177
|
} catch (Exception e) {
|
188
178
|
|
@@ -190,8 +180,6 @@
|
|
190
180
|
|
191
181
|
}
|
192
182
|
|
193
|
-
log.info("service end." + i);
|
194
|
-
|
195
183
|
}
|
196
184
|
|
197
185
|
}
|