线程池 抓取数据库信息

@Async(ThreadPoolConfig.EXECUTOR_NAME)
public void transferData() throws SQLException, CloneNotSupportedException {
		
	String srcUrl = DBURL.getURL(DBURL.DBTYPE_SQLSERVER, "10.10.1.47", "1433", "srcdbname");
	String srcUser = "sa";
	String srcPasswd = "123456";
		
	String targetUrl = DBURL.getURL(DBURL.DBTYPE_MYSQL, "10.10.1.47", "3306", "targetdbname");
	String targetUser = "root";
	String targetPasswd = "123456";
		
	DruidDataSource srcDataSource = createDataSource(DBURL.DBTYPE_SQLSERVER, srcUrl, srcUser, srcPasswd);
	SqlRunner srcSqlRunner = SqlRunner.create(srcDataSource);
	DruidDataSource targetDataSource = createDataSource(DBURL.DBTYPE_MYSQL, targetUrl, targetUser, targetPasswd);
	SqlRunner targetSqlRunner = SqlRunner.create(targetDataSource);
		
	List dictionaryWordList = srcSqlRunner.findAll("srctbname");
	List targetDictionaryWordList = new ArrayList<>();
	for (Entity entity : dictionaryWordList) {
			
	        Entity targetEntity = Entity.create("targettbname")
			            .set("targetfield1", entity.getObj("srcfield1"))
				    .set("targetfield2", entity.getObj("srcfield2"));
			
	        targetDictionaryWordList.add(targetEntity);
	}
		
	logger.info("写入开始时间:" + new Date().toString());
	targetSqlRunner.insert(targetDictionaryWordList);
	logger.info("写入结束时间:" + new Date().toString());
		
	srcDataSource.clone();
	targetDataSource.close();
}

http://hutool.mydoc.io/

个人笔记,仅供参考

你可能感兴趣的:(代码常用知识)