From ee18dad45f6dc1926bdf8725e7150b658ea09a1b Mon Sep 17 00:00:00 2001 From: liujian <46431414+lj2018110133@users.noreply.github.com> Date: Sat, 26 Dec 2020 16:30:00 +0800 Subject: [PATCH] optimize: globalTransactionScanner listener optimize (#3380) --- changes/1.5.0.md | 2 ++ changes/en-us/1.5.0.md | 2 ++ .../seata/spring/annotation/GlobalTransactionScanner.java | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/changes/1.5.0.md b/changes/1.5.0.md index 69f9d75a5..60495cf59 100644 --- a/changes/1.5.0.md +++ b/changes/1.5.0.md @@ -43,6 +43,7 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗� - [[#3359](https://github.com/seata/seata/pull/3359)] 鍒犻櫎鏈娇鐢ㄧ殑娴嬭瘯鐢ㄤ緥 - [[#3397](https://github.com/seata/seata/pull/3397)] 娣诲姞鏇存敼璁板綍鏂囦欢澶� - [[#3303](https://github.com/seata/seata/pull/3303)] 鏀寔浠巒acos鍗曚竴dataId涓鍙栨墍鏈夐厤缃� + - [[#3380](https://github.com/seata/seata/pull/3380)] 浼樺寲globalTransactionScanner鐩戝惉鍣� @@ -63,6 +64,7 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗� - [anselleeyy](https://github.com/anselleeyy) - [Ifdevil](https://github.com/Ifdevil) - [Rubbernecker](https://github.com/Rubbernecker) + - [lj2018110133](https://github.com/lj2018110133) 鍚屾椂锛屾垜浠敹鍒颁簡绀惧尯鍙嶉鐨勫緢澶氭湁浠峰€肩殑issue鍜屽缓璁紝闈炲父鎰熻阿澶у銆� diff --git a/changes/en-us/1.5.0.md b/changes/en-us/1.5.0.md index fb4364e98..45ff694fc 100644 --- a/changes/en-us/1.5.0.md +++ b/changes/en-us/1.5.0.md @@ -42,6 +42,7 @@ - [[#3359](https://github.com/seata/seata/pull/3359)] remove unused test case - [[#3397](https://github.com/seata/seata/pull/3397)] add the change records folder - [[#3303](https://github.com/seata/seata/pull/3303)] supports reading all configurations from a single Nacos dataId + - [[#3380](https://github.com/seata/seata/pull/3380)] globalTransactionScanner listener optimize ### test @@ -59,6 +60,7 @@ - [anselleeyy](https://github.com/anselleeyy) - [Ifdevil](https://github.com/Ifdevil) - [Rubbernecker](https://github.com/Rubbernecker) + - [lj2018110133](https://github.com/lj2018110133) Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java index a03ed9d78..6afe974d8 100644 --- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java +++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java @@ -329,12 +329,12 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator @Override public void afterPropertiesSet() { - ConfigurationCache.addConfigListener(ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, - (ConfigurationChangeListener)this); if (disableGlobalTransaction) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Global transaction is disabled."); } + ConfigurationCache.addConfigListener(ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, + (ConfigurationChangeListener)this); return; } if (initialized.compareAndSet(false, true)) { @@ -351,10 +351,10 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator @Override public void onChangeEvent(ConfigurationChangeEvent event) { if (ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION.equals(event.getDataId())) { - LOGGER.info("{} config changed, old value:{}, new value:{}", ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, - disableGlobalTransaction, event.getNewValue()); disableGlobalTransaction = Boolean.parseBoolean(event.getNewValue().trim()); if (!disableGlobalTransaction && initialized.compareAndSet(false, true)) { + LOGGER.info("{} config changed, old value:{}, new value:{}", ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, + disableGlobalTransaction, event.getNewValue()); initClient(); } } -- GitLab