Big Data split processing mode

Source: Internet
Author: User
Tags log log

Ideas:
1: Refer to Paging to split data into a specified size number of threads
2: Read the data and process the data in each separate thread
Step One implementation

 Public classIndexintitools { Public StaticAtomicinteger runflag=NewAtomicinteger (); //for testing     Public StaticList<object> synclist=NewCopyonwritearraylist<object>(); Private Static intIdxthreadcount = 10; Private StaticExecutor ex =Executors.newfixedthreadpool (Idxthreadcount); /*** Build Index *@paramHQL *@paramsize*/     Public Static voidBuild (String hql,intsize) {        intPageCount =Idxthreadcount; intCount = Size/PageCount; intMoD = size%PageCount; List<Runnable> runlist =NewArraylist<runnable>(PageCount);        Indexexecutor Idxexecutor;  for(inti = 0; i < PageCount; i++) {            if(i = = (pagecount-1) ) {Idxexecutor=NewIndexexecutor (HQL, I * count, Count +MoD); } Else{idxexecutor=NewIndexexecutor (HQL, I *count, Count);        } runlist.add (Idxexecutor); }         for(Runnable runnable:runlist) {runflag.incrementandget ();        Ex.execute (runnable); }    }}

Step Two implementation

 Public classIndexexecutorImplementsrunnable{Private Static FinalLog log = Logfactory.getlog (indexexecutor.class); Private intstart; Private intlimit; PrivateString hql;  PublicIndexexecutor (String hql,intStartintlimit) {         This. hql=hql;  This. Start =start;  This. Limit =limit; } @Override Public voidrun () {Log.info ("HQL:" +hql+ ", Start:" +start+ ", limit" +limit); //Query Database (hql,start,limit);log.info (list);        IndexIntiTools.syncList.addAll (list);    IndexIntiTools.runflag.decrementAndGet (); }}

Big Data split processing mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.