diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java index a653a24dd2b..01bce191e07 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java @@ -72,7 +72,7 @@ class AtomikosJtaConfiguration { .getIfAvailable(); } - @Bean(initMethod = "init", destroyMethod = "shutdownForce") + @Bean(initMethod = "init", destroyMethod = "shutdownWait") @ConditionalOnMissingBean(UserTransactionService.class) public UserTransactionServiceImp userTransactionService( AtomikosProperties atomikosProperties) { diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 16367627835..bea1dd81f8b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -749,6 +749,7 @@ content into your application. Rather, pick only the properties that you need. spring.jta.atomikos.properties.allow-sub-transactions=true # Specify whether sub-transactions are allowed. spring.jta.atomikos.properties.checkpoint-interval=500 # Interval between checkpoints, in milliseconds. spring.jta.atomikos.properties.default-jta-timeout=10000 # Default timeout for JTA transactions, in milliseconds. + spring.jta.atomikos.properties.default-max-wait-time-on-shutdown=9223372036854775807 # How long should normal shutdown (no-force) wait for transactions to complete. spring.jta.atomikos.properties.enable-logging=true # Whether to enable disk logging. spring.jta.atomikos.properties.force-shutdown-on-vm-exit=false # Whether a VM shutdown should trigger forced shutdown of the transaction core. spring.jta.atomikos.properties.log-base-dir= # Directory in which the log files should be stored. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java index 6a03d099d31..303d954e58b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosProperties.java @@ -82,6 +82,11 @@ public class AtomikosProperties { */ private boolean forceShutdownOnVmExit; + /** + * How long should normal shutdown (no-force) wait for transactions to complete. + */ + private long defaultMaxWaitTimeOnShutdown = Long.MAX_VALUE; + /** * Transactions log file base name. */ @@ -107,6 +112,7 @@ public class AtomikosProperties { private final Recovery recovery = new Recovery(); + /** * Specifies the transaction manager implementation that should be started. There is * no default value and this must be set. Generally, @@ -236,6 +242,19 @@ public class AtomikosProperties { return this.forceShutdownOnVmExit; } + /** + * Specifies how long should a normal shutdown (no-force) wait for transactions to complete. + * Defaults to {@literal Long.MAX_VALUE}. + * @param defaultMaxWaitTimeOnShutdown the default max wait time on shutdown + */ + public void setDefaultMaxWaitTimeOnShutdown(long defaultMaxWaitTimeOnShutdown) { + this.defaultMaxWaitTimeOnShutdown = defaultMaxWaitTimeOnShutdown; + } + + public long getDefaultMaxWaitTimeOnShutdown() { + return this.defaultMaxWaitTimeOnShutdown; + } + /** * Specifies the transactions log file base name. Defaults to {@literal tmlog}. The * transactions logs are stored in files using this name appended with a number and @@ -316,6 +335,8 @@ public class AtomikosProperties { set(properties, "serial_jta_transactions", isSerialJtaTransactions()); set(properties, "allow_subtransactions", isAllowSubTransactions()); set(properties, "force_shutdown_on_vm_exit", isForceShutdownOnVmExit()); + set(properties, "default_max_wait_time_on_shutdown", + getDefaultMaxWaitTimeOnShutdown()); set(properties, "log_base_name", getLogBaseName()); set(properties, "log_base_dir", getLogBaseDir()); set(properties, "checkpoint_interval", getCheckpointInterval()); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java index 0565dd16622..79d6937f315 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java @@ -49,6 +49,7 @@ public class AtomikosPropertiesTests { this.properties.setSerialJtaTransactions(true); this.properties.setAllowSubTransactions(false); this.properties.setForceShutdownOnVmExit(true); + this.properties.setDefaultMaxWaitTimeOnShutdown(20); this.properties.setLogBaseName("logBaseName"); this.properties.setLogBaseDir("logBaseDir"); this.properties.setCheckpointInterval(4); @@ -58,7 +59,7 @@ public class AtomikosPropertiesTests { this.properties.getRecovery().setDelay(Duration.ofMillis(3000)); this.properties.getRecovery().setMaxRetries(10); this.properties.getRecovery().setRetryInterval(Duration.ofMillis(4000)); - assertThat(this.properties.asProperties().size()).isEqualTo(17); + assertThat(this.properties.asProperties().size()).isEqualTo(18); assertProperty("com.atomikos.icatch.service", "service"); assertProperty("com.atomikos.icatch.max_timeout", "1"); assertProperty("com.atomikos.icatch.default_jta_timeout", "2"); @@ -68,6 +69,7 @@ public class AtomikosPropertiesTests { assertProperty("com.atomikos.icatch.serial_jta_transactions", "true"); assertProperty("com.atomikos.icatch.allow_subtransactions", "false"); assertProperty("com.atomikos.icatch.force_shutdown_on_vm_exit", "true"); + assertProperty("com.atomikos.icatch.default_max_wait_time_on_shutdown", "20"); assertProperty("com.atomikos.icatch.log_base_name", "logBaseName"); assertProperty("com.atomikos.icatch.log_base_dir", "logBaseDir"); assertProperty("com.atomikos.icatch.checkpoint_interval", "4"); @@ -89,6 +91,7 @@ public class AtomikosPropertiesTests { "com.atomikos.icatch.serial_jta_transactions", "com.atomikos.icatch.allow_subtransactions", "com.atomikos.icatch.force_shutdown_on_vm_exit", + "com.atomikos.icatch.default_max_wait_time_on_shutdown", "com.atomikos.icatch.log_base_name", "com.atomikos.icatch.checkpoint_interval", "com.atomikos.icatch.threaded_2pc", @@ -97,7 +100,7 @@ public class AtomikosPropertiesTests { "com.atomikos.icatch.oltp_retry_interval")); assertThat(properties).contains(entry("com.atomikos.icatch.recovery_delay", defaultSettings.get("com.atomikos.icatch.default_jta_timeout"))); - assertThat(properties).hasSize(14); + assertThat(properties).hasSize(15); } private MapEntry[] defaultOf(Properties defaultSettings, String... keys) {