当前位置:网站首页>Using multithreaded callable to query Oracle Database
Using multithreaded callable to query Oracle Database
2022-07-02 00:05:00 【Hu Bayi】
Use single threaded queries 10 Ten thousand data are too slow , Use multithreading to query , Increase of efficiency .
ThredQuery Method of querying data
public class ThredQuery implements Callable<List<HashVO>> {
private MyUtil util = new MyUtil();
private int bindex;// The current number of pages
private int num;// How many queries per page
private List page;// The data found in each page
private String customerName;
private String customerType;
private String idType;
private String idNumb;
private String updateTime;
public ThredQuery(int bindex,int num,String customerName, String customerType, String idType, String idNumb, String updateTime) {
this.bindex=bindex;
this.num=num;
this.customerName=customerName;
this.customerType=customerType;
this.idType=idType;
this.idNumb=idNumb;
this.updateTime=updateTime;
}
@Override
public List<HashVO> call() throws Exception {
String sql = "";
if (StringUtils.isNotBlank(customerName)) {
sql += " and customer_name like '%" + customerName + "%' ";
}
if (StringUtils.isNotBlank(customerType)) {
sql += " and customer_type = '" + customerType + "' ";
}
if (StringUtils.isNotBlank(idType)) {
sql += " and id_type = '" + idType + "' ";
}
if (StringUtils.isNotBlank(idNumb)) {
sql += " and id_numb like '%" + idNumb + "%' ";
}
if (StringUtils.isNotBlank(updateTime)) {
sql += " and (" + updateTime + ")";
}
sql += " order by id";
String finalSql = "SELECT * FROM " +
"(" +
"SELECT A.*, ROWNUM RN " +
"FROM ("
+ sql +
" ) A " +
" WHERE ROWNUM <= "+ (bindex*num)+
" ) " +
"WHERE RN >= "+(((bindex-1)*num)+1);
return Arrays.asList(util.getHashVOs(finalSql));
}
}
Be careful :call Inside is the query method .util Is to query data , perform sql
oracle Paging method , With pageIndex and pageSize For example
String sql= "SELECT * FROM " +
"(" +
"SELECT A.*, ROWNUM RN " +
"FROM ("
+ sql +
" ) A " +
" WHERE ROWNUM <= "+ (pageIndex*pageSize)+
" ) " +
"WHERE RN >= "+(((pageIndex-1)*pageSize)+1);
Calling method :
private void getVoListMultiThreading(String customerName, String customerType, String idType, String idNumb, String updateTime) {
long start = System.currentTimeMillis();// Starting time
List<HashVO> result = new ArrayList<>();// Return results
// Query the total number of databases
int count = queryCount();
int num = 8000;// How many items are queried at a time
// Number of queries required
int times = count / num;
if (count % num != 0) {
times = times + 1;
}
// Start page number The connection is orcle The database of Encapsulated paging Mine is from 1 Start
//Callable Used to produce results
List<Callable<List<HashVO>>> tasks = new ArrayList<>();
for (int i = 1; i <= times; i++) {
// Multithreaded query
Callable<List<HashVO>> qfe = new ThredQuery(i, num, customerName, customerType, idType, idNumb, updateTime);
tasks.add(qfe);
}
// Define a fixed length thread pool Prevent too many threads
ExecutorService executorService = Executors.newFixedThreadPool(15);
//Future Used to get results
try {
List<Future<List<HashVO>>> futures=executorService.invokeAll(tasks);
// The processing thread returns the result
if(futures!=null&&futures.size()>0){
for (Future<List<HashVO>> future:futures){
result.addAll(future.get());
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
executorService.shutdown();// Close thread pool
long end = System.currentTimeMillis();// End time
log.info(" Query time consuming :" + (end - start) / 1000 + " second "," result : "+result);
}
Query time is only used 30s
边栏推荐
- Using SqlCommand objects in code
- ADO. Net SqlConnection object usage summary
- I would like to ask, which securities is better for securities account opening? Is it safe to open a mobile account?
- The essence of software architecture
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- 在证券账户上买基金安全吗?哪里可以买基金
- [QT] test whether QT can connect to the database
- [QT] qtcreator uninstall and installation (abnormal state)
- [cmake] cmake configuration in QT Creator
- MySQL Replication中并行复制怎么实现
猜你喜欢

.env.xxx 文件,加了常量,卻undefined

Kubernetes resource object introduction and common commands (III)

Overview of edge calculation

SQL数据分析之窗口排序函数rank、dense_rank、raw_number与lag、lead窗口偏移函数【用法整理】

使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object

使用多线程Callable查询oracle数据库

Asp . Text of automatic reply to NETCORE wechat subscription number

Windows10 install WSL (I) (wslregisterdistribution error)

kubernetes资源对象介绍及常用命令(三)

2021 robocom world robot developer competition - semi finals of higher vocational group
随机推荐
kubernetes资源对象介绍及常用命令(三)
ADO. Net SqlDataAdapter object
[es practice] safe operation mode on ES
实例讲解将Graph Explorer搬上JupyterLab
Three methods of finding inverse numbers
MySQL Replication中并行复制怎么实现
第六章 数据流建模
【QT】测试Qt是否能连接上数据库
13 MySQL constraint
.env.xxx 文件,加了常量,卻undefined
在证券账户上买基金安全吗?哪里可以买基金
Resumption of attack and defense drill
[QT] qtcreator uninstall and installation (abnormal state)
Jielizhi Bluetooth headset quality control and production skills [chapter]
安全协议重点
Regular expression collection
LDR6035智能蓝牙音响可对手机设备持续充放电方案
JPA handwritten SQL, received with user-defined entity classes
Key points of security agreement
Use the htaccess file to prohibit the script execution permission in the directory