|
|
|
|
@ -46,16 +46,14 @@ import java.util.concurrent.*;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*源码下载
|
|
|
|
|
* 源码下载
|
|
|
|
|
* https://download.csdn.net/download/lxyoucan/85094574
|
|
|
|
|
*
|
|
|
|
|
* <p>
|
|
|
|
|
* 参考
|
|
|
|
|
* https://github.com/freakchick/DBApi
|
|
|
|
|
*
|
|
|
|
|
*SpringBoot中封装jdbc工具类
|
|
|
|
|
* <p>
|
|
|
|
|
* SpringBoot中封装jdbc工具类
|
|
|
|
|
* https://blog.csdn.net/lxyoucan/article/details/124042295
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@ -80,6 +78,7 @@ public class JdbcDemoController {
|
|
|
|
|
// ds.setId("2");
|
|
|
|
|
// ds.setName("oracle");
|
|
|
|
|
// ds.setUrl("jdbc:oracle:thin:@192.168.1.9:1521/orcl");
|
|
|
|
|
// ds.setUrl("jdbc:oracle:thin:@192.168.3.7:1521/orcl");
|
|
|
|
|
// ds.setUsername("appserver");
|
|
|
|
|
// ds.setPassword("appserver");
|
|
|
|
|
// ds.setDriver("oracle.jdbc.driver.OracleDriver");
|
|
|
|
|
@ -87,11 +86,11 @@ public class JdbcDemoController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询测试
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
//@RequestMapping("/api/list")
|
|
|
|
|
public ResponseDto queryList() {
|
|
|
|
|
|
|
|
|
|
// 自定义一个线程池,内部包含8个线程
|
|
|
|
|
ExecutorService customPool = Executors.newFixedThreadPool(8);
|
|
|
|
|
// 自定义一个线程池,内部包含10个线程
|
|
|
|
|
@ -99,14 +98,8 @@ public class JdbcDemoController {
|
|
|
|
|
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
String sql = "select * from temperature where id = ?";
|
|
|
|
|
List<Object> jdbcParamValues = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < 2362254; i++) {
|
|
|
|
|
// try {
|
|
|
|
|
// Thread.sleep(5);
|
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
for (int i = 2292104; i < 2298700; i++) {
|
|
|
|
|
jdbcParamValues.add(i + 1);
|
|
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
ResponseDto responseDto = JdbcUtil.executeSql(ds, sql, jdbcParamValues);
|
|
|
|
|
String dbQueryResult = gson.toJson(responseDto);
|
|
|
|
|
@ -116,7 +109,6 @@ public class JdbcDemoController {
|
|
|
|
|
ResponseTemperatureDto responseTemperatureDto = gson.fromJson(dbQueryResult, ResponseTemperatureDto.class);
|
|
|
|
|
if (responseTemperatureDto.isSuccess() && responseTemperatureDto.getData() != null && responseTemperatureDto.getData().size() > 0) {
|
|
|
|
|
log.info(gson.toJson(responseTemperatureDto.getData().get(0)));
|
|
|
|
|
|
|
|
|
|
TemperatureDto dto = responseTemperatureDto.getData().get(0);
|
|
|
|
|
Temperature temperature = new Temperature();
|
|
|
|
|
temperature.setCreateDate(dto.getCreateDate());
|
|
|
|
|
@ -131,7 +123,7 @@ public class JdbcDemoController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "数据库同步成功";
|
|
|
|
|
},customPool);
|
|
|
|
|
}, customPool);
|
|
|
|
|
|
|
|
|
|
future.thenApply(result -> {
|
|
|
|
|
System.out.println("Result: " + result);
|
|
|
|
|
@ -157,6 +149,7 @@ public class JdbcDemoController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询测试
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/api/getResult")
|
|
|
|
|
@ -172,7 +165,7 @@ public class JdbcDemoController {
|
|
|
|
|
Thread.currentThread().interrupt(); // 重置中断状态
|
|
|
|
|
}
|
|
|
|
|
return "数据库同步成功";
|
|
|
|
|
},executorService);
|
|
|
|
|
}, executorService);
|
|
|
|
|
//注意,如果需要异步返回结果,再做后续操作,需要加入join()方法等待异步计算结果后回调,不然异步没有处理完直接主线程结束
|
|
|
|
|
future.thenApply(result -> {
|
|
|
|
|
System.out.println("Result: " + result);
|
|
|
|
|
@ -184,6 +177,7 @@ public class JdbcDemoController {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询测试
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/api/getResult0")
|
|
|
|
|
@ -193,7 +187,7 @@ public class JdbcDemoController {
|
|
|
|
|
String result = CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
System.out.println("Step 1: Generate number");
|
|
|
|
|
return 42;
|
|
|
|
|
},executorService).thenApply(num -> {
|
|
|
|
|
}, executorService).thenApply(num -> {
|
|
|
|
|
System.out.println("Step 2: Convert number to string");
|
|
|
|
|
return "Number is: " + num;
|
|
|
|
|
}).exceptionally(exception -> {
|
|
|
|
|
@ -201,7 +195,7 @@ public class JdbcDemoController {
|
|
|
|
|
return null;
|
|
|
|
|
}).join();
|
|
|
|
|
|
|
|
|
|
if(TextUtils.isEmpty(result)){
|
|
|
|
|
if (TextUtils.isEmpty(result)) {
|
|
|
|
|
return "数据库同步异常...";
|
|
|
|
|
}
|
|
|
|
|
System.out.println("数据库正在同步...");
|
|
|
|
|
|