Home > Java > javaTutorial > How to process java multi-threaded data in pages

How to process java multi-threaded data in pages

WBOY
Release: 2023-04-18 22:04:01
forward
1279 people have browsed it

1. Common paging types

Traditional: Using the traditional paging method, you can clearly obtain data information, such as how many pieces of data there are, how many pages to display, etc.

Drop-down: Using the drop-down paging method, it is generally impossible to obtain clear information related to the number of data, but after the paging operation, you can still see the previously queried data.

2. Paging query logic

int pageSize = 100;
int currentPageLength = 0;
int pageIndex = 0;
ExecutorService exe  = newFixedThreadPool(Runtime.getRuntime().availableProcessors());
do {
    int offset = pageIndex * pageSize;
    List<TradeInfo> tradeInfos = tradeInfoService.findTradeInfoBysPage(queryParams,offset,pageSize);
    if (null != tradeInfos && tradeInfos.size() > 0) {
        currentPageLength = tradeInfos.size();
        TradeInfoProcesserTask task = new TradeInfoProcesserTask(tradeInfos );
        exe.execute(task);
        pageIndex++;
    }else{
        System.out.println("Page Query TradeInfo Got NOTHING! Break query loop!");
        break;
    }
} while (currentPageLength == pageSize);
 
exe.shutdown();
 
while(true) {
    if(exe.isTerminated()){
        doOtherThings();
        System.out.println("分页式多线程处理数据完毕!");
        break;
    }
}
Copy after login

3. Data processing logic

public class TradeInfoProcesserTask implements Runnable{
    private volatile List<TradeInfo> tradeInfos;
    
    public TradeInfoProcesserTask (List<TradeInfo> _tradeInfos){
        tradeInfos = _tradeInfos;
    }
    
    @Override
    public void run() {
        processTradeInfos();
    }
    
    private void processTradeInfos(){
        //do something with tradeInfos .....
    }
}
Copy after login

The above is the detailed content of How to process java multi-threaded data in pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template