背景:アプリケーションシステムが政府で開発されました。主な機能は、エンタープライズにエンタープライズの資格情報を埋めることができ、与えられた式を使用してこの一連の情報をカウントし、スコアの形で政府リーダーに表示することです。現在、1,300社がレポートに記入しています。スコアはリアルタイムで表示されるため、統計関数は遅いです。
コード実行プロセス:
1. 1300の企業情報をご覧ください
2. 1300エンタープライズ情報を通過し、各エンタープライズのスコア情報を計算します。各企業の時間は0.3秒であると予想されています。合計390秒。ページリクエストタイムアウトを引き起こします
3。エクスポート(JXL JARを使用)
解決:
ビジネスを処理するため、値を返すことができるスレッドが必要です。使用:呼び出し可能
コードを直接アップロードします
1.スレッドを呼び出すコード
List <Map <String、Object >> list =(list <map <string、object >>)map.get( "rows"); int tasksize = 20; //スレッドプールexecustorservice pool = executors.newfixedththreadpool(tasksize); //リターン値で複数のタスクを作成するリスト<未来> listfuture = new arraylist < i ++){system.out.println( "私はマルチスレッドラララ")将来のオブジェクトを取得して将来のf = pool.submit(c); listfuture.add(f);} pool.shutdown(); //すべての並行タスクの実行結果を取得<map <string、object >> listresult = new arraylist <map <string、object >>();(future f:listfuture、<map <arrist、< object >>(); try {listmodel =(list <map <map <string、object >>)f.get();} catch(arturnedexception e){e.printstacktrace();} catch(executionexception e){e.printstacktrace();} listresult.addall(listmodel);} map.put "2。スレッドコード
usi.jszx.controller; import java.util.list; import java.util.map; import java.util.concurrent.callable; import javax.servlet.http.httpsession; import org.apache.commons.lang3.stringutils; Import usi.jsxx.cor.scoremain; usi.jszx.service.declaremasterservice; import usi.jszx.service.declareservice; Import usi.jszx.service.declareservice; import usi.jszx.service.enterprisequeryservice; import usi.sys.dto.authinfo; usi.sys.util.constantutil; class mycallableは<オブジェクト> calkable>を実装します {//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- myCallable(list <map <string、object >> list、httpsession Session、string staticflag、declareRemasterService declareMasterService、expersequeryserservice EnterpriseQueryservice){this.list = list; this.session = session; Staticflag = staticflag; declareService; this.declaremasterservice = declaremasterservice; this.enterprisequeryservice = empersiequeryservice;}@overridepublic object call()throws {authinfo)session.getattribute(constantutil.auth_info); {map <string、object> maplist = list.get(i); string mainid = maplist.get( "id")+""; this.grademaster(session、mainid、maplist.get.get( "orgid")+""、dedraremasterservice、EnterprisequeryService);リスト<マップ<文字列> declaremasterservice.queryscoremain(maplist.get( "id")+""、info.getrighttype()、 "eport"); // declemasterservice.queryscoremain(mainid、info.getRightType()、isReport); int isdouble = 1; listscore.get(46).get( "score")); isdouble = 2;} else if(listscore.size()> 22){maplist.put( "socretotal"、listscore.get( "score"));} if( "3"。 {if(j <9){maplist.put( "value0"+(j+1)、listscore.get(j*isdouble).get( "show_value"));} else {balue "+(j+1)、listscore.get(j*isdouble).get(" show_value "); maplist.get( "CountyId")+""; if( "340826" .equals(countyid)|| "341822" .equals(countyid)){maplist.put( "cityname"、maplist.get( "countyname")+"");} maplist.get( "declare_evaluate")+""; if( "1" .equals(declare_evaluate)){maplist.put( "declare_evaluate_name"、 "declaration");} maplist.get( "shstatus")+""; if( "9" .equals(shstatus)){maplist.put( "strshstatus"、 "draft");} else if( "0" .equals(shstatus)){maplist.put( "strshstatus"、 "Enterprise submiss"); if( "1" .equals(shstatus)){maplist.put( "strshstatus"、 "city review passed");} else if( "2" .equals(shstatus)){maplist.put( "strshstatus"、 "City Review Passed"); "Provincial Review Passed");} else if( "4" .equals(shstatus)){maplist.put( "strshstatus"、 "provincial review failed");} else if( "5" .equals(shstatus)){maplist.put( "strshstatus"); if( "6" .equals(shstatus)){maplist.put( "strshstatus"、 "Return to Enterprise Modification");} else if( "7" .equals(shstatus)){maplist.put( "strshstatus"、 "city review");} elth if( "11"(shstatus)) to declaration");} else if("12".equals(SHSTATUS)){maplist.put("STRSHSTATUS", "Modify to evaluation");}if("1".equals(staticFlag)){//Add a modification opinion List<Map<String, Object>> listDetail = declareService.queryAuditLog(mainId); if(listdetail.size()> 0){string audit_opinion = listdetail.get(0).get( "audit_opinion")+""; if(!stringutils.isempty(audit_opinion)&&! "null"。 else {maplist.put( "audit_opinion"、 "");}} // string orgname = maplist.get( "orgname")+""; string pjname = maplist.get( "pjname")+""; if(stringutils.isempty(pjname)|| "null" .equals(pjname)|| pjname.equals(orgname)){maplist.put( "isgengming"、 "no"); maplist.put( "pjname_e"); " else {maplist.put( "isgengming"、 "yes"); maplist.put( "pjname_e"、pjname);} else if( "2" .equals(staticflag){}} return list;} public float grademaster(httpsession session、string mainid) EnterpriseQueryService){authinfo info =(authinfo)session.getAttribute(constingutil.auth_info); string righttype = info.getRightType(); DelaremasterService.DeletesCoreMain(Mainid); Float [] resultfirst = new Float [100];テーブルデータ * *レビューが作成されているため、メインテーブルデータは保存する必要があります * */list <Map <String、objectdetail = decraremasterservice.querytaskdetail(mainid); if( "2" .equals(righttype)|| "3" .equals(righttype)) {map <string、object> map = listdetail.get(i); if(stringutils.isempty(map.edare_city_value ")+" ")||" null ".equals(" decrare_city_value ")+" ")){resultfirst [i] = 0f; float.parsefloat(map.get( "declare_city_value")+"");}}}} leth {// stringをfloatforに変換する(int i = 0; i <listdetail.size(); i ++){map <string、object> map = map = listdetail.get(i); if(stringutils.isempty(map.get( "declare_province_value")+"")|| "null" .equals( "declare_province_value")+""))){resultfirst [i] = 0f;} els {resultfirst [i] = float.parsefloat(map.get( "declare_province_value")+"");}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} entinfobyorgid(orgid)。次のステップは、スコアフロート比1 = 0f;フロート比2 = 0f;フロート比3 = 0f;トライ{比率1 = float.parsefloat(enterprise.get( "ratio1")+"");比率を計算することです。 float.parsefloat(Enterprise.get( "ratio3")+"");} catch(Exception e){} Map <String、Object> Map = decrarecontroller.getValue(resultFirst、ratio1、ratio2、ratio2); float [] resultvalue =(float =(float "); float"); "float"); map.get( "resultscorevalue"); float [] resultscore = deularecontroller.getScore(resultscorevalue); float scoretotal = 0f; list <map <string、objectscore = decremasterservice.queryscoredic(); scoremain(); scoremain.setmainid(mainid); scoremain.setscorename(listscore.get(i).get( "score_name")+""); scoremain.setscoreunit(listscore.get(i).get( "score_unit")+""); scoremain.setscoreweight(listscore.get(i).get( "score_weight")+""); scoremain.setscoreweight(listscore.get(i).get( "score_weight")+""); scoremain in.setdisorder(listscore.get(i).get( "dis_order")+""); scoremain.setShowValue(resultValue [i]+""); scoremain.setscorevalue(resultscorevalue [i]+""); scoremain.setscore(resultscore [i]+""); decraremasterservice.inserscoremain(scoremain); scoretotal += resultscore [i];} return scoretotal;}}注:MyCallableは、ビジネスを扱う複雑な方法です。それは無視することができ、最後に390秒から40秒にスピードアップします。
要約します
上記は、Java Multi-Threaded実行と事業時間の処理時間のソリューションコードの例に関するこの記事のコンテンツ全体です。私はそれが誰にでも役立つことを願っています。興味のある友人は、このサイトの他の関連トピックを引き続き参照できます。欠点がある場合は、それを指摘するためにメッセージを残してください。このサイトへのご支援をありがとうございました!