Commit fd2f3d3
committed
Replace timeout handling to use SharedTimer
Replaces the timeout handling for basic and bulk TDS commands to use a new SharedTimer
class. SharedTimer provides a static method for fetching an existing static object or
creating one on demand. Usage is tracked through reference counting and callers are
required to call removeRef() when they will no longer be using the SharedTimer. If the
SharedTimer does not have any more references then its internal ScheduledThreadPoolExecutor
will be shutdown.
The SharedTimer is cached at the Connection level so that repeated invocations do not
create new timers. Connections only create timers on first use so if no actions involve
a timeout then no timer is fetched or created. If a Connection does create a timer then
it will be released when the Connection closed.
Properly written JDBC applications that always close their Connection objects when
they are finished using them should not have any extra threads running after they are
all closed. Applications that do not use query timeouts will not have any extra threads
created as they are only done on demand. Applications that use timeouts and use
a JDBC connection pool will have a single shared object across all JDBC connections as
long as there are some open connections in the pool with timeouts enabled.
Interrupt actions to handle a timeout are executed in their own thread. A handler thread is
created when the timeout occurs with the thread name matching the connection id of the
client connection that created the timeout. If the timeout is canceled prior to the interrupt
action being executed, say because the command finished, then no handler thread is created.
Note that the sharing of the timers happens across all Connections, not just Connections
with the same JDBC URL and properties.1 parent d639870 commit fd2f3d3
File tree
10 files changed
+226
-226
lines changed- src/main/java/com/microsoft/sqlserver/jdbc
10 files changed
+226
-226
lines changedLines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
Lines changed: 17 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
3016 | 3017 | | |
3017 | 3018 | | |
3018 | 3019 | | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
3019 | 3024 | | |
3020 | 3025 | | |
3021 | 3026 | | |
| |||
6236 | 6241 | | |
6237 | 6242 | | |
6238 | 6243 | | |
6239 | | - | |
| 6244 | + | |
6240 | 6245 | | |
6241 | 6246 | | |
6242 | 6247 | | |
| |||
6390 | 6395 | | |
6391 | 6396 | | |
6392 | 6397 | | |
6393 | | - | |
6394 | | - | |
6395 | | - | |
| 6398 | + | |
| 6399 | + | |
6396 | 6400 | | |
6397 | 6401 | | |
6398 | 6402 | | |
| |||
6413 | 6417 | | |
6414 | 6418 | | |
6415 | 6419 | | |
6416 | | - | |
6417 | | - | |
| 6420 | + | |
| 6421 | + | |
| 6422 | + | |
6418 | 6423 | | |
6419 | 6424 | | |
6420 | 6425 | | |
| |||
7003 | 7008 | | |
7004 | 7009 | | |
7005 | 7010 | | |
7006 | | - | |
7007 | | - | |
7008 | | - | |
7009 | | - | |
7010 | | - | |
7011 | | - | |
7012 | | - | |
7013 | | - | |
7014 | | - | |
7015 | | - | |
7016 | | - | |
7017 | | - | |
7018 | | - | |
7019 | | - | |
7020 | | - | |
7021 | | - | |
7022 | | - | |
7023 | | - | |
7024 | | - | |
7025 | | - | |
7026 | | - | |
7027 | | - | |
7028 | | - | |
7029 | | - | |
7030 | | - | |
7031 | | - | |
7032 | | - | |
7033 | | - | |
7034 | | - | |
7035 | | - | |
7036 | | - | |
7037 | | - | |
7038 | | - | |
7039 | | - | |
7040 | | - | |
7041 | | - | |
7042 | 7011 | | |
7043 | 7012 | | |
7044 | 7013 | | |
| |||
7160 | 7129 | | |
7161 | 7130 | | |
7162 | 7131 | | |
7163 | | - | |
| 7132 | + | |
7164 | 7133 | | |
7165 | 7134 | | |
7166 | 7135 | | |
| |||
7576 | 7545 | | |
7577 | 7546 | | |
7578 | 7547 | | |
7579 | | - | |
7580 | | - | |
| 7548 | + | |
| 7549 | + | |
7581 | 7550 | | |
7582 | 7551 | | |
7583 | 7552 | | |
| |||
7600 | 7569 | | |
7601 | 7570 | | |
7602 | 7571 | | |
7603 | | - | |
7604 | | - | |
| 7572 | + | |
| 7573 | + | |
| 7574 | + | |
7605 | 7575 | | |
7606 | 7576 | | |
7607 | 7577 | | |
| |||
Lines changed: 20 additions & 56 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 250 | + | |
274 | 251 | | |
275 | 252 | | |
276 | 253 | | |
| |||
646 | 623 | | |
647 | 624 | | |
648 | 625 | | |
649 | | - | |
650 | | - | |
651 | 626 | | |
652 | 627 | | |
653 | 628 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
659 | 633 | | |
660 | 634 | | |
661 | 635 | | |
| |||
671 | 645 | | |
672 | 646 | | |
673 | 647 | | |
674 | | - | |
675 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
676 | 659 | | |
677 | 660 | | |
678 | 661 | | |
679 | 662 | | |
680 | 663 | | |
681 | 664 | | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
687 | 668 | | |
688 | | - | |
689 | 669 | | |
690 | 670 | | |
691 | 671 | | |
| |||
1145 | 1125 | | |
1146 | 1126 | | |
1147 | 1127 | | |
1148 | | - | |
1149 | | - | |
1150 | | - | |
1151 | | - | |
1152 | | - | |
1153 | | - | |
1154 | | - | |
1155 | | - | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | 1128 | | |
1165 | 1129 | | |
1166 | 1130 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
| |||
3174 | 3186 | | |
3175 | 3187 | | |
3176 | 3188 | | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
3177 | 3194 | | |
3178 | 3195 | | |
3179 | 3196 | | |
| |||
Lines changed: 64 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments