Spring系列(五)Spring的多執行緒

2021-10-04 03:59:38 字數 895 閱讀 8345

spring通過任務執行器(taskexecutor)來實現多執行緒和併發程式設計。使用thredpooltaskexecutor可以實現基於執行緒池的taskexecutor。

為了實現非同步任務,可以在配置類中通過@enable開啟對非同步任務的支援,並通過實際執行的bean的方法使用@async註解來宣告是乙個非同步任務

配置類

/**

* 配置類

* @enableasync 開啟非同步任務

* @author zhaojiaxing

* @version 1.0

* @date 2020/02/14 16:57

*/@configuration

@componentscan("com.zjx.spring.async")

@enableasync

public class taskexecutorconfig implements asyncconfigurer

@override

public asyncuncaughtexceptionhandler getasyncuncaughtexceptionhandler()

}

任務執行類

@service

public class asynctaskservice

@async

public void executeasynctaskplus(integer i)

}

執行

public class main 

context.close();

}}``

spring基礎(五) spring事物

一 事務的概念 事物 是使用者定義的一系列操作序列,這些動作要麼都做,要麼都不做,是乙個不可分割的工作單位 事物提交 資料庫向使用者提供儲存當前程式狀態的方法 事物回滾 資料庫忽略當前的狀態並回到前面儲存的狀態的方法 二 事務特性 原子性 一致性 隔離性 永續性 三 spring事務 enablet...

Spring專案開發筆記系列(五)

spring專案開發筆記系列 五 hibernate持久化類的annotation方式配置 spring的這個專案中主要用的配置檔案就前面這麼幾個web.xml,spring config.xml和struts config.xml,其它的配置檔案比如log4j.properties,validat...

Spring系列教程 03Spring容器的建立

new beans.xml 第二種 檔案系統路徑獲得配置檔案 絕對路徑 new d springframework講解 src beans.xml 第三種 使用beanfactory 了解 newxmlbeanfactory new filesystemresource d springframew...