<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一、概述 比如輪詢大量的記錄,這種job,可能會一次輪詢耗時數個小時到數天,那么,對于業務來說,是無法接受的;這個時候,平臺支持通過引入派生多線程的并發解決方案; ## 二、解決方案 通過動態派生多線程來實現;平臺中,通過提供RayCaller和RayThread來實現(實際上,除了調度服務,所有需要動態多線程的場景,這兩個平臺提供的基礎設施類,都能提供幫助); 下面通過一個例子來說明; ``` @Component public class MultiThreadJobSample extends RayPeriodScheduleJob { @Override public boolean enabled() { return true; } @Override public String jobDesc() { return "多線程驗證"; } @Override public long periodInSeconds() { return 1 * minute; } @Override public long initialDelayInSeconds() { return 1 * minute; } @Override public String allowedIps() { return all; } @Autowired private RunCaller runCaller; @Override public void doInRayPeriodJob(SysJobExecution sysjobexecution) { int totalSize=10000; int sizePerThread=1000; List<Long> idList = new ArrayList(); for (long i = 0; i < totalSize; i++) { idList.add(i); } // 將待輪詢的大列表,依據條目進行分組,每個分組規劃一個線程執行 List<List<Long>> threadSplitList = ListUtil.splitListByPerListSize(idList, sizePerThread); int threadNum = threadSplitList.size(); runCaller.call(logger, threadNum, threadSplitList, sysjobexecution); } @Component public static class RunCaller extends RayCaller { @Override public void createThreadToExecutionTask(Logger logger, int threadNum, ExecutorService executor, CountDownLatch currentMainThreadLatch) { // 依據分配好的線程輪詢對象,每個線程分配均勻的條目輪詢對象列表 for (int i = 0; i < threadNum; i++) { List<List<Long>> threadSplitList = getMainTranferdBusinessObject(0); List<Long> listPer = threadSplitList.get(i); Runnable task = new RunThread(logger, i+ 1, currentMainThreadLatch, appendToEndOfMainTranferdAsCallerTransferedBusinessObjects(listPer)); executor.execute(task); } } } public static class RunThread extends RayThread { public RunThread(Logger logger, int threadIndex, CountDownLatch callerCountDownLatch, Object[] callerTranferdBusinessObjects) { super(logger, threadIndex, callerCountDownLatch, callerTranferdBusinessObjects); } @Override public void doBusinessInThread(Object[] callerTranferdBusinessObjects) { logger.error("{}開始運行", Thread.currentThread().getName()); SysJobExecution sysjobexecution = getCallerTranferdBusinessObject(1); List<Long> threadSplitList = getCallerTranferdBusinessObject(2); StringBuilder errorMessage = getCallerTranferdBusinessObject(3); // 針對當前線程需要需要處理的輪詢對象,進行輪詢 for (int i = 0; i < threadSplitList.size(); i++) { try { //可能拋異常的代碼 } catch(Exception ex) { errorMessage.append(ExceptionUtil.getFullStackTraceAsString(e)); } logger.error("處理了第{}條", threadSplitList.get(i)); } } } } ``` >[danger] RunThread 中的doBusinessInThread,才是真正執行業務的地方;
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看