Mysql多執行緒插入10萬資料

2021-09-29 18:26:18 字數 1445 閱讀 5710

1.excel中匯入資料到mongo暫存(可能多次匯入,防止重複,所以暫存)

@responsebody

@apioperation("匯入任務v2")

public dggrestresponse importbyexcel(@param("file") multipartfile file) catch (ioexception e)

list> result = new arraylist>();

int size = xssfwk.getnumberofsheets();

xssfrow namerow = xssfwk.getsheetat(0).getrow(0);

arraylisttasks = new arraylist<>();

for(int numsheet=0;numsheetrowlist = new arraylist<>();

basicdbobject document = new basicdbobject();

system.out.println("****"+rownum+".....");

importtask task = new importtask();

for(int colix=mincolix;colix2.從mongo讀取資料,並存入mysql中

(1):在啟動類上,先初始化執行緒池大小

@importresource(locations = )

public static void main(string args)

@bean

public executor executor() }}

(2):準備號插入資料的執行緒

@slf4j

public class importdatathread implements runnable

@override

public void run() catch (exception e)

}countdownlatch.countdown();

}}

(3)插入mysql

public hashmapimportdata(long roomid) 

try catch (interruptedexception e)

}elseelse

}try catch (interruptedexception e) }}

result.put("successtotal",successtotal.get());

result.put("failtotal",failtotal.get());

return result;

}

多執行緒 10 執行緒副本

threadlocal 執行緒副本的使用 執行緒副本類主要解決的就是,要每個單獨的執行緒,都繫結自己執行緒內部共享的值,可以想象每個執行緒都有自己的 threadlocal 筆記本,這個筆記本上記載著所有該執行緒自身的共享變數 class mythreadlocal public string ge...

多執行緒處理mysql資料

閒來無事研究了下py,發現多執行緒處理起資料來比php不要爽太多,廢話少說上碼 author yao import mydb from time import ctime,sleep def mythread db for i in xrange 10 sql select from y user ...

mybatis使用多執行緒批量插入資料

昨天在專案中有乙個excel導表的操作,於是就想著用多執行緒插入資料。網上找了下mabayis多執行緒插入資料,看了很多都是配置的xml,但我不是很喜歡寫xml.於是自己手寫了乙個,可能不是很優雅,但還是記錄一下.不多說,直接上 controller,和dao就不放了,主要是service層 ove...