fuyou001 commented on code in PR #8663: URL: https://github.com/apache/rocketmq/pull/8663#discussion_r1804206899
########## store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java: ########## @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.store.lock; + +import org.apache.rocketmq.store.config.MessageStoreConfig; + +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +public class AdaptiveBackOffSpinLockImpl implements AdaptiveBackOffSpinLock { + private AdaptiveBackOffSpinLock adaptiveLock; + //state + private AtomicBoolean state = new AtomicBoolean(true); + + private final static float SWAP_SPIN_LOCK_RATIO = 0.8f; + + private final static int SPIN_LOCK_ADAPTIVE_RATIO = 4; + + private final static int BASE_SWAP_LOCK_RATIO = 320; + + private Map<String, AdaptiveBackOffSpinLock> locks; + + private final List<AtomicInteger> tpsTable; + + private final List<Map<Thread, Byte>> threadTable; + + private int swapCriticalPoint; + + private AtomicInteger currentThreadNum = new AtomicInteger(0); + + private AtomicBoolean isOpen = new AtomicBoolean(true); + + public AdaptiveBackOffSpinLockImpl() { + this.locks = new HashMap<>(); + this.locks.put("Reentrant", new BackOffReentrantLock()); Review Comment: These strings use class constants. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org