当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentHashMap.remove方法代码示例

本文整理汇总了Java中java.util.concurrent.ConcurrentHashMap.remove方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentHashMap.remove方法的具体用法?Java ConcurrentHashMap.remove怎么用?Java ConcurrentHashMap.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ConcurrentHashMap的用法示例。


在下文中一共展示了ConcurrentHashMap.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMapClean

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@Test
public void testMapClean() throws InterruptedException{
	ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<String, String>();
	long lastCleanTimestamp = new Date().getTime();
	int cleanInterval = 2;
	cache.put("key1", "foo-" + new Date().getTime());
	Thread.sleep(500);
	cache.put("key2", "foo-" + new Date().getTime());
	Assert.assertEquals(cache.size(), 2);
	Thread.sleep(1700);
	long now = new Date().getTime();
	if((now-lastCleanTimestamp)/1000>=cleanInterval){
		lastCleanTimestamp = now;
		Iterator<Entry<String, String>> iter = cache.entrySet().iterator();
		while(iter.hasNext()){
			Entry<String, String> entry = iter.next();
			String key = entry.getKey();
			String value = entry.getValue();
			long valueTimestamp = Long.parseLong(value.substring(value.length()-13));
			if(valueTimestamp < now-cleanInterval*1000){
				cache.remove(key);
			}
		}
	}
	Assert.assertEquals(cache.size(), 1);
}
 
开发者ID:jweixin,项目名称:jwx,代码行数:27,代码来源:TimeTest.java

示例2: cmnClearRegion

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public void cmnClearRegion(long drId,
    ConcurrentHashMap<DiskStoreID, RegionVersionHolder<DiskStoreID>> memberToVersion) {
  DiskRegionView drv = getDiskRegionById(drId);
  if (drv.getClearRVV() == null) {
    this.ifLiveRecordCount++;
  }
  // otherwise previous clear is cancelled so don't change liveRecordCount
  this.ifTotalRecordCount++;

  DiskStoreID ownerId = parent.getDiskStoreID();
  // Create a fake RVV for clear purposes. We only need to memberToVersion information
  RegionVersionHolder<DiskStoreID> ownerExceptions = memberToVersion.remove(ownerId);
  long ownerVersion = ownerExceptions == null ? 0 : ownerExceptions.getVersion();
  RegionVersionVector rvv = new DiskRegionVersionVector(ownerId, memberToVersion, ownerVersion,
      new ConcurrentHashMap(), 0L, false, ownerExceptions);
  drv.setClearRVV(rvv);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:DiskInitFile.java

示例3: removeMethodFromMethodsMap

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Remove method from methods map.
 *
 * @param mTargetMap      the target map.
 * @param targetObject    the target object.
 * @param targetChannelId the target channel ids.
 */
private void removeMethodFromMethodsMap(ConcurrentHashMap<Object,
        ConcurrentHashMap<String, SubscriberHolder>> mTargetMap,
                                        Object targetObject,
                                        List<String> targetChannelId) {
    ConcurrentHashMap<String, SubscriberHolder> mSubscribedMethodsMap =
            mTargetMap.get(targetObject);
    for (Map.Entry<String, SubscriberHolder> mSubscribedMethodsMapEntry :
            mSubscribedMethodsMap.entrySet()) {
        SubscriberHolder subscribedMethod = mSubscribedMethodsMapEntry.getValue();
        List<String> methodChannelId = subscribedMethod.subscribedChannelID;
        if (targetChannelId.containsAll(methodChannelId)) {
            mSubscribedMethodsMap.remove(mSubscribedMethodsMapEntry.getKey());
            removeTargetIfRequired(mSubscribedMethodsMap, mTargetMap, targetObject);
        }
    }
}
 
开发者ID:MindorksOpenSource,项目名称:NYBus,代码行数:24,代码来源:NYBusDriver.java

示例4: testSetValueWriteThrough

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * SetValue of an EntrySet entry sets value in the map.
 */
public void testSetValueWriteThrough() {
    // Adapted from a bug report by Eric Zoerner
    ConcurrentHashMap map = new ConcurrentHashMap(2, 5.0f, 1);
    assertTrue(map.isEmpty());
    for (int i = 0; i < 20; i++)
        map.put(new Integer(i), new Integer(i));
    assertFalse(map.isEmpty());
    Map.Entry entry1 = (Map.Entry)map.entrySet().iterator().next();
    // Unless it happens to be first (in which case remainder of
    // test is skipped), remove a possibly-colliding key from map
    // which, under some implementations, may cause entry1 to be
    // cloned in map
    if (!entry1.getKey().equals(new Integer(16))) {
        map.remove(new Integer(16));
        entry1.setValue("XYZ");
        assertTrue(map.containsValue("XYZ")); // fails if write-through broken
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ConcurrentHashMapTest.java

示例5: remove

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public void remove(K1 key1, K2 key2) {
    ConcurrentHashMap<K2, V> k2_v = k1_k2V_map.get(key1);
    if (k2_v != null) {
        k2_v.remove(key2);
    }
    if (k2_v == null || k2_v.isEmpty()) {
        k1_k2V_map.remove(key1);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:DoubleKeyValueMap.java

示例6: execute

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void execute(JobExecutionContext job) throws JobExecutionException {
	TriggerScheduleServiceCenterToProviderServiceCenterMessage msg = new TriggerScheduleServiceCenterToProviderServiceCenterMessage();
	String jobName = job.getJobDetail().getKey().getName();
	JobDataMap jobDataMap = job.getJobDetail().getJobDataMap();
	ConcurrentHashMap<Integer, ServiceXServerSession> rpcServers = (ConcurrentHashMap<Integer, ServiceXServerSession>) jobDataMap
			.get(RPCSERVERS);
	ConcurrentHashMap<String, ConcurrentHashSet<Integer>> schedules = (ConcurrentHashMap<String, ConcurrentHashSet<Integer>>) jobDataMap
			.get(SCHEDULES);
	ConcurrentHashSet<Integer> providerList = schedules.get(jobName);
	if (providerList == null) {
		log.error("Job:" + jobName + "找不到Provider");
		return;
	}
	msg.setJobName(jobName);
	// 查看是否是最有一次执行,并且移除此job
	if (!job.getTrigger().mayFireAgain()) {
		msg.setEnd(true);
		schedules.remove(jobName);
		log.info("任务生命终结,执行删除:" + jobName);
	}
	// 选举式触发
	ArrayList<Integer> arrayList = new ArrayList<>(providerList);
	int providerId = arrayList.get(RandomUtil.randomInt(0, arrayList.size() - 1));
	ServiceXServerSession serviceXServerSession = rpcServers.get(providerId);
	if (serviceXServerSession != null) {
		serviceXServerSession.getSession().writeAndFlush(msg);
		log.info(jobName + "触发!分配的ProviderId为:" + providerId + ",下次触发时间:"
				+ TimeUtil.date2Str(job.getTrigger().getNextFireTime().getTime()));
	}
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:33,代码来源:ScheduleTask.java

示例7: removeOldest

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Sort QueryStats by last invocation time
 * @param queries
 */
protected void removeOldest(ConcurrentHashMap<String,QueryStats> queries) {
    ArrayList<QueryStats> list = new ArrayList<QueryStats>(queries.values());
    Collections.sort(list, queryStatsComparator);
    int removeIndex = 0;
    while (queries.size() > maxQueries) {
        String sql = list.get(removeIndex).getQuery();
        queries.remove(sql);
        if (log.isDebugEnabled()) log.debug("Removing slow query, capacity reached:"+sql);
        removeIndex++;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:SlowQueryReport.java

示例8: removeTargetIfRequired

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Remove the target.
 *
 * @param subscribedMethods the subscribed methods.
 * @param mTargetMap        the target map.
 * @param targetObject      the target object.
 */
private void removeTargetIfRequired(ConcurrentHashMap<String, SubscriberHolder> subscribedMethods,
                                    ConcurrentHashMap<Object,
                                            ConcurrentHashMap<String, SubscriberHolder>> mTargetMap,
                                    Object targetObject) {
    if (subscribedMethods.size() == 0) {
        mTargetMap.remove(targetObject);
    }
}
 
开发者ID:MindorksOpenSource,项目名称:NYBus,代码行数:16,代码来源:NYBusDriver.java

示例9: processQueue

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * Removes weak keys from the map that have been enqueued
 * on the reference queue and are no longer in use.
 */
private static void processQueue(ReferenceQueue<Key> queue,
                                 ConcurrentHashMap<? extends
                                 WeakReference<Key>, ?> pdMap) {
    Reference<? extends Key> ref;
    while ((ref = queue.poll()) != null) {
        pdMap.remove(ref);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:ProtectionDomain.java

示例10: WeakKey

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public WeakKey(K key, Cleaner c, ConcurrentHashMap<WeakKey<K>, ?> map) {
    super(key);
    this.hash = key.hashCode();
    this.map = map;
    cleanable = new WeakCleanable<Object>(key, c) {
        protected void performCleanup() {
            map.remove(WeakKey.this);
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:CleanerTest.java

示例11: testRemove

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * remove removes the correct key-value pair from the map
 */
public void testRemove() {
    ConcurrentHashMap map = map5();
    map.remove(five);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ConcurrentHashMapTest.java

示例12: testRemove2

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * remove(key,value) removes only if pair present
 */
public void testRemove2() {
    ConcurrentHashMap map = map5();
    map.remove(five, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
    map.remove(four, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(four));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ConcurrentHashMapTest.java

示例13: testRemove1_NullPointerException

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    ConcurrentHashMap c = new ConcurrentHashMap(5);
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ConcurrentHashMapTest.java

示例14: testRemove2_NullPointerException

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
/**
 * remove(null, x) throws NPE
 */
public void testRemove2_NullPointerException() {
    ConcurrentHashMap c = new ConcurrentHashMap(5);
    c.put("sadsdf", "asdads");
    try {
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ConcurrentHashMapTest.java

示例15: unlockBatch

import java.util.concurrent.ConcurrentHashMap; //导入方法依赖的package包/类
public void unlockBatch(final String group, final Set<MessageQueue> mqs, final String clientId) {
    try {
        this.lock.lockInterruptibly();
        try {
            ConcurrentHashMap<MessageQueue, LockEntry> groupValue = this.mqLockTable.get(group);
            if (null != groupValue) {
                for (MessageQueue mq : mqs) {
                    LockEntry lockEntry = groupValue.get(mq);
                    if (null != lockEntry) {
                        if (lockEntry.getClientId().equals(clientId)) {
                            groupValue.remove(mq);
                            log.info("unlockBatch, Group: {} {} {}",
                                group,
                                mq,
                                clientId);
                        } else {
                            log.warn("unlockBatch, but mq locked by other client: {}, Group: {} {} {}",
                                lockEntry.getClientId(),
                                group,
                                mq,
                                clientId);
                        }
                    } else {
                        log.warn("unlockBatch, but mq not locked, Group: {} {} {}",
                            group,
                            mq,
                            clientId);
                    }
                }
            } else {
                log.warn("unlockBatch, group not exist, Group: {} {}",
                    group,
                    clientId);
            }
        } finally {
            this.lock.unlock();
        }
    } catch (InterruptedException e) {
        log.error("putMessage exception", e);
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:42,代码来源:RebalanceLockManager.java


注:本文中的java.util.concurrent.ConcurrentHashMap.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。