@@ -398,26 +398,34 @@ void checkAndCloseSpanners(CheckAndCloseSpannersMode mode) {
|
398 | 398 | keysStillInUse.add(entry.getKey());
|
399 | 399 | }
|
400 | 400 | }
|
401 |
| -if (keysStillInUse.isEmpty() || mode == CheckAndCloseSpannersMode.WARN) { |
402 |
| -if (!keysStillInUse.isEmpty()) { |
| 401 | +try { |
| 402 | +if (keysStillInUse.isEmpty() || mode == CheckAndCloseSpannersMode.WARN) { |
| 403 | +if (!keysStillInUse.isEmpty()) { |
| 404 | +logConnections(keysStillInUse); |
| 405 | +logger.log( |
| 406 | +Level.WARNING, |
| 407 | +"There is/are " |
| 408 | ++ keysStillInUse.size() |
| 409 | ++ " connection(s) still open." |
| 410 | ++ " Close all connections before stopping the application"); |
| 411 | +} |
| 412 | +// Force close all Spanner instances by passing in a value that will always be less than |
| 413 | +// the |
| 414 | +// difference between the current time and the close time of a connection. |
| 415 | +closeUnusedSpanners(Long.MIN_VALUE); |
| 416 | +} else { |
403 | 417 | logConnections(keysStillInUse);
|
404 |
| -logger.log( |
405 |
| -Level.WARNING, |
| 418 | +throw SpannerExceptionFactory.newSpannerException( |
| 419 | +ErrorCode.FAILED_PRECONDITION, |
406 | 420 | "There is/are "
|
407 | 421 | + keysStillInUse.size()
|
408 |
| -+ " connection(s) still open." |
409 |
| -+ " Close all connections before stopping the application"); |
| 422 | ++ " connection(s) still open. Close all connections before calling closeSpanner()"); |
410 | 423 | }
|
411 |
| -// Force close all Spanner instances by passing in a value that will always be less than the |
412 |
| -// difference between the current time and the close time of a connection. |
413 |
| -closeUnusedSpanners(Long.MIN_VALUE); |
414 |
| -} else { |
415 |
| -logConnections(keysStillInUse); |
416 |
| -throw SpannerExceptionFactory.newSpannerException( |
417 |
| -ErrorCode.FAILED_PRECONDITION, |
418 |
| -"There is/are " |
419 |
| -+ keysStillInUse.size() |
420 |
| -+ " connection(s) still open. Close all connections before calling closeSpanner()"); |
| 424 | +} finally { |
| 425 | +if (closerService != null) { |
| 426 | +closerService.shutdown(); |
| 427 | +} |
| 428 | +initialized = false; |
421 | 429 | }
|
422 | 430 | }
|
423 | 431 | }
|
|
0 commit comments