this.brokerLiveTable = new HashMap<String, BrokerLiveInfo>(256); */
public void scanNotActiveBroker() {
    Iterator<Entry<String, BrokerLiveInfo>> it = 
this.brokerLiveTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, BrokerLiveInfo> next = it.next();
        long last = next.getValue().getLastUpdateTimestamp();
        if ((last + BROKER_CHANNEL_EXPIRED_TIME) < System.currentTimeMillis()) {
            RemotingUtil.closeChannel(next.getValue().getChannel());
            it.remove();
            log.warn("The broker channel expired, {} {}ms", next.getKey(), 
BROKER_CHANNEL_EXPIRED_TIME);
            this.onChannelDestroy(/**brokerAddress*/next.getKey(), 
/**长连接channel*/next.getValue().getChannel());
        }
    }
}首先这是rocketmq中扫描存活broker的一段代码,我认为这段代码是存在线程安全性问题。在一些情况下,如在使用Iterator便利这个map时,有新的broker注册进来,会抛出java.util.ConcurrentModificationException。





Reply via email to