org.apache.rocketmq.common.utils.ThreadUtils Java Examples

The following examples show how to use org.apache.rocketmq.common.utils.ThreadUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionRecordFlush2DBService.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    log.info(this.getServiceName() + " service started");

    while (!this.isStopped()) {
        try {
            DispatchRequestCollections requests = dispatchRequestBufferQueue.peek();
            if (requests.requestlist.size() > FLOW_CONTROLLER / REQUEST_BUFFER_IN_QUEUE
                    || flushCounter > CHECK_THREAD_LOOP) {
                this.doFlushDB(false);
                flushCounter = 0;
                continue;
            }
            ++flushCounter;
            ThreadUtils.sleep(10);
        } catch (Exception e) {
            log.warn(this.getServiceName() + " service has exception. ", e);
        }
    }
    log.info(this.getServiceName() + " service end");
}
 
Example #2
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public ReputMessageService() {
    if (messageStoreConfig.isReputConcurrentEnable() && messageStoreConfig.getReputConcurrentThreadCount() > 0) {
        isReputConcurrentEnable = true;
        currentThreadCount = messageStoreConfig.getReputConcurrentThreadCount();
        executors = new ExecutorService[currentThreadCount];
        for (int i = 0; i < currentThreadCount; i++) {
            executors[i] = ThreadUtils.newSingleThreadExecutor("ReputMessageConcurrent_" + i, false);
        }
    } else {
        isReputConcurrentEnable = false;
        currentThreadCount = 0;
    }
}
 
Example #3
Source File: ConsumeMessageOrderlyService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void shutdown(long awaitTerminateMillis) {
    this.stopped = true;
    this.scheduledExecutorService.shutdown();
    ThreadUtils.shutdownGracefully(this.consumeExecutor, awaitTerminateMillis, TimeUnit.MILLISECONDS);
    if (MessageModel.CLUSTERING.equals(this.defaultMQPushConsumerImpl.messageModel())) {
        this.unlockAllMQ();
    }
}
 
Example #4
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public ReputMessageService() {
    if (messageStoreConfig.isReputConcurrentEnable() && messageStoreConfig.getReputConcurrentThreadCount() > 0) {
        isReputConcurrentEnable = true;
        currentThreadCount = messageStoreConfig.getReputConcurrentThreadCount();
        executors = new ExecutorService[currentThreadCount];
        for (int i = 0; i < currentThreadCount; i++) {
            executors[i] = ThreadUtils.newSingleThreadExecutor("ReputMessageConcurrent_" + i, false);
        }
    } else {
        isReputConcurrentEnable = false;
        currentThreadCount = 0;
    }
}
 
Example #5
Source File: PullMessageService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #6
Source File: ConsumeMessageConcurrentlyService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void shutdown(long awaitTerminateMillis) {
    this.scheduledExecutorService.shutdown();
    ThreadUtils.shutdownGracefully(this.consumeExecutor, awaitTerminateMillis, TimeUnit.MILLISECONDS);
    this.cleanExpireMsgExecutors.shutdown();
}
 
Example #7
Source File: PullMessageService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #8
Source File: LocalMessageCache.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #9
Source File: TransactionRecordFlush2DBService.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
private void doFlushDB(boolean shutdown) {
    DispatchRequestCollections requests = dispatchRequestBufferQueue.poll();
    if (requests == null) {
        return;
    }
    if (!shutdown) {
        putEmptyRequestList();
    }
    boolean addSuccess = false, removeSuccess = false;
    LinkedHashMap<Long, TransactionRecord> prepareTrs = null;
    LinkedHashMap<Long, Void> confirmTrs = null;
    while (true) {
        if (requests.latch.get() != requests.requestlist.size() && requests.latch.get() > 0) {
            continue;
        }
        requests.latch.set(Integer.MIN_VALUE);

        if (requests.requestlist.size() == 0) {
            break;
        }
        try {
            long transactionOffset = -1L;
            //数据处理
            if (prepareTrs == null && confirmTrs == null) {
                prepareTrs = new LinkedHashMap<Long, TransactionRecord>();
                confirmTrs = new LinkedHashMap<Long, Void>();
                for (DispatchRequest request : requests.requestlist) {
                    final int tranType = MessageSysFlag.getTransactionValue(request.getSysFlag());
                    switch (tranType) {
                        case MessageSysFlag.TRANSACTION_NOT_TYPE:
                            break;
                        case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                            if (this.maxTransOffset.get() < request.getCommitLogOffset()) {
                                prepareTrs.put(request.getCommitLogOffset(), new TransactionRecord(request.getCommitLogOffset(),
                                        request.getCheckImmunityTimeOutTimestamp(), request.getMsgSize(), request.getProducerGroup()));
                                this.maxTransOffset.set(request.getCommitLogOffset());
                            } else {
                                log.info("[PREPARED] request ignore offset =" + request.getCommitLogOffset());
                            }
                            if (request.getPreparedTransactionOffset() == 0L) {
                                break;
                            }
                        case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                            if (this.maxTransOffset.get() < request.getCommitLogOffset()) {
                                if (prepareTrs.containsKey(request.getPreparedTransactionOffset())) {
                                    prepareTrs.remove(request.getPreparedTransactionOffset());
                                } else {
                                    confirmTrs.put(request.getPreparedTransactionOffset(), null);
                                }
                            } else {
                                log.info("[COMMIT] request ignore offset =" + request.getCommitLogOffset()
                                        + ",isCommitMessge=" + (tranType == MessageSysFlag.TRANSACTION_COMMIT_TYPE));
                            }
                            break;
                    }
                }
                transactionOffset = requests.requestlist.get(requests.requestlist.size() - 1).getCommitLogOffset();
            }

            long startTime = System.currentTimeMillis();
            addSuccess = addSuccess || transactionStore.parpare(new ArrayList<>(prepareTrs.values()));
            if (addSuccess && (removeSuccess = transactionStore.confirm(new ArrayList<>(confirmTrs.keySet())))) {
                log.info("pull TransactionRecord consume {}ms ,size={},realParpareSize={},realConfirmSize:{}",
                        (System.currentTimeMillis() - startTime), requests.requestlist.size(), prepareTrs.size(), confirmTrs.size());
                //更新最新的offset
                if (transactionOffset > 0) {
                    transactionOffsetConifgService.putOffset(transactionOffset);
                }
                break;
            }
        } catch (Throwable e) {
            log.error("transactionStore error:", e);
            ThreadUtils.sleep(2000);
        } finally {
            if (addSuccess && removeSuccess) {
                flowController.release(requests.requestlist.size());
            }
        }
    }
}
 
Example #10
Source File: PullMessageService.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #11
Source File: LocalMessageCache.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #12
Source File: LocalMessageCache.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #13
Source File: LocalMessageCache.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #14
Source File: PullMessageService.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #15
Source File: LocalMessageCache.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #16
Source File: DeFiBusPullMessageService.java    From DeFiBus with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.executorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #17
Source File: PullMessageService.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example #18
Source File: LocalMessageCache.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example #19
Source File: PullMessageService.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}