天天看點

【spring boot】13.在spring boot下使用多線程

使用場景:

方法處理到某一步,需要将資訊交給另一個線程去處理!!

===================================================================================

第一種:最簡單的Runnable

====================================================================================================

第二種:自己建立JDK線程池,交給spring管理,然後将任務交給線程池即可

1.建立線程池,交給spring管理

【spring boot】13.在spring boot下使用多線程
【spring boot】13.在spring boot下使用多線程

View Code

2.使用它

【spring boot】13.在spring boot下使用多線程
【spring boot】13.在spring boot下使用多線程

第三種:使用spring封裝的線程池

1.建立線程配置類【

【spring boot】13.在spring boot下使用多線程
【spring boot】13.在spring boot下使用多線程

2.建立線程任務執行類

【spring boot】13.在spring boot下使用多線程
【spring boot】13.在spring boot下使用多線程

3.使用它

【spring boot】13.在spring boot下使用多線程
【spring boot】13.在spring boot下使用多線程

======================================

就這麼多,再補充噻!!