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


Java GcFinalization.awaitFullGc方法代码示例

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


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

示例1: testMultiThreadedUse

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
private void testMultiThreadedUse(int numMainExceptions, int numSuppressedPerMain)
    throws InterruptedException {
  CountDownLatch latch = new CountDownLatch(numMainExceptions * numSuppressedPerMain);
  ConcurrentWeakIdentityHashMap map =
      testFunctionalCorrectnessForMultiThreadedUse(
          numMainExceptions, numSuppressedPerMain, latch);
  /*
   * Calling the following methods multiple times to make sure the keys are garbage collected,
   * and their corresponding entries are removed from the map.
   */
  map.deleteEmptyKeys();
  GcFinalization.awaitFullGc();
  map.deleteEmptyKeys();
  GcFinalization.awaitFullGc();
  map.deleteEmptyKeys();

  assertThat(map.size()).isEqualTo(0);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:19,代码来源:ConcurrentWeakIdentityHashMapTest.java

示例2: testEviction

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction() {
  TestState state = new TestState();
  Key<Integer> key = Key.get(Integer.class);
  Object source = new Object();
  
  WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

  set.add(key, state, source);
  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source));

  state = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(Key.get(Integer.class)));
  assertNull(set.getSources(Key.get(Integer.class)));

  // Ensure there are no hanging references.
  key = null;
  GcFinalization.awaitClear(weakKeyRef);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:WeakKeySetTest.java

示例3: testEviction_nullSource

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_nullSource() {
  TestState state = new TestState();
  Key<Integer> key = Key.get(Integer.class);
  Object source = null;
  
  WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

  set.add(key, state, source);
  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source));

  state = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(Key.get(Integer.class)));
  assertNull(set.getSources(Key.get(Integer.class)));

  // Ensure there are no hanging references.
  key = null;
  GcFinalization.awaitClear(weakKeyRef);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:WeakKeySetTest.java

示例4: testSingleThreadedUse

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@Test
public void testSingleThreadedUse() throws InterruptedException {
  CountDownLatch latch = new CountDownLatch(5);
  ConcurrentWeakIdentityHashMap map =
      testConcurrentWeakIdentityHashMapSingleThreadedHelper(latch);
  for (int i = 0; i < 5; i++) {
    map.deleteEmptyKeys();
    GcFinalization.awaitFullGc();
  }
  latch.await(); // wait for e1 to be garbage collected.
  map.deleteEmptyKeys();
  assertThat(map.size()).isEqualTo(0);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:ConcurrentWeakIdentityHashMapTest.java

示例5: testNoEviction_keyOverlap_2x

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testNoEviction_keyOverlap_2x() {
  TestState state1 = new TestState();
  TestState state2 = new TestState();
  Key<Integer> key1 = Key.get(Integer.class);
  Key<Integer> key2 = Key.get(Integer.class);
  Object source1 = new Object();
  Object source2 = new Object();

  set.add(key1, state1, source1);
  assertTrue(set.contains(key1));
  assertEquals(1, set.getSources(key1).size());
  assertTrue(set.getSources(key1).contains(source1));

  set.add(key2, state2, source2);
  assertTrue(set.contains(key2));
  assertEquals(2, set.getSources(key2).size());
  assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));

  WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
  WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);

  Key<Integer> key = key1 = key2 = Key.get(Integer.class);

  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));
  assertEquals(2, set.getSources(key).size());
  assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));

  // Ensure the keys don't get GC'd when states are still referenced. key1 will be present in the
  // as the map key but key2 could be GC'd if the implementation does something wrong.
  assertNotNull(weakKey1Ref.get());
  assertNotNull(weakKey2Ref.get());
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:35,代码来源:WeakKeySetTest.java

示例6: testEviction_keyOverlap_2x

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_keyOverlap_2x() {
  TestState state1 = new TestState();
  TestState state2 = new TestState();
  Key<Integer> key1 = Key.get(Integer.class);
  Key<Integer> key2 = Key.get(Integer.class);
  Object source1 = new Object();
  Object source2 = new Object();

  set.add(key1, state1, source1);
  assertTrue(set.contains(key1));
  assertEquals(1, set.getSources(key1).size());
  assertTrue(set.getSources(key1).contains(source1));

  set.add(key2, state2, source2);
  assertTrue(set.contains(key2));
  assertEquals(2, set.getSources(key2).size());
  assertTrue(set.getSources(key2).containsAll(Arrays.asList(source1, source2)));

  WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
  WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
  WeakReference<Object> weakSource1Ref = new WeakReference<Object>(source1);
  WeakReference<Object> weakSource2Ref = new WeakReference<Object>(source2);

  Key<Integer> key = key1 = key2 = Key.get(Integer.class);
  state1 = null;

  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source2));
  assertFalse(set.getSources(key).contains(source1));

  source1 = source2 = null;
  
  GcFinalization.awaitClear(weakSource1Ref);
  // Key1 will be referenced as the key in the sources backingSet and won't be
  // GC'd.
  
  // Should not be GC'd until state2 goes away.
  assertNotNull(weakSource2Ref.get());

  state2 = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(key));
  assertNull(set.getSources(key));

  GcFinalization.awaitClear(weakKey2Ref);
  GcFinalization.awaitClear(weakSource2Ref);
  // Now that the backing set is emptied, key1 is released.
  GcFinalization.awaitClear(weakKey1Ref);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:55,代码来源:WeakKeySetTest.java

示例7: testEviction_keyAndSourceOverlap_null

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_keyAndSourceOverlap_null() {
  TestState state1 = new TestState();
  TestState state2 = new TestState();
  Key<Integer> key1 = Key.get(Integer.class);
  Key<Integer> key2 = Key.get(Integer.class);
  Object source = null;

  set.add(key1, state1, source);
  assertTrue(set.contains(key1));
  assertEquals(1, set.getSources(key1).size());
  assertTrue(set.getSources(key1).contains(source));

  set.add(key2, state2, source);
  assertTrue(set.contains(key2));

  // Same source so still only one value.
  assertEquals(1, set.getSources(key2).size());
  assertTrue(set.getSources(key1).contains(source));

  WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
  WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
  WeakReference<Object> weakSourceRef = new WeakReference<Object>(source);

  Key<Integer> key = key1 = key2 = Key.get(Integer.class);
  state1 = null;

  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));

  // Should still have a single source.
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key1).contains(source));
  
  source = null;

  GcFinalization.awaitClear(weakSourceRef);
  // Key1 will be referenced as the key in the sources backingSet and won't be
  // GC'd.

  state2 = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(key));
  assertNull(set.getSources(key));

  GcFinalization.awaitClear(weakKey2Ref);
  GcFinalization.awaitClear(weakSourceRef);
  // Now that the backing set is emptied, key1 is released.
  GcFinalization.awaitClear(weakKey1Ref);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:53,代码来源:WeakKeySetTest.java

示例8: testEviction_keyAndSourceOverlap_nonNull

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_keyAndSourceOverlap_nonNull() {
  TestState state1 = new TestState();
  TestState state2 = new TestState();
  Key<Integer> key1 = Key.get(Integer.class);
  Key<Integer> key2 = Key.get(Integer.class);
  Object source = new Object();

  set.add(key1, state1, source);
  assertTrue(set.contains(key1));
  assertEquals(1, set.getSources(key1).size());
  assertTrue(set.getSources(key1).contains(source));

  set.add(key2, state2, source);
  assertTrue(set.contains(key2));

  // Same source so still only one value.
  assertEquals(1, set.getSources(key2).size());
  assertTrue(set.getSources(key1).contains(source));

  WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
  WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
  WeakReference<Object> weakSourceRef = new WeakReference<Object>(source);

  Key<Integer> key = key1 = key2 = Key.get(Integer.class);
  state1 = null;

  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));

  // Should still have a single source.
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key1).contains(source));
  
  source = null;

  GcFinalization.awaitFullGc();
  assertNotNull(weakSourceRef.get());
  // Key1 will be referenced as the key in the sources backingSet and won't be
  // GC'd.

  state2 = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(key));
  assertNull(set.getSources(key));

  GcFinalization.awaitClear(weakKey2Ref);
  GcFinalization.awaitClear(weakSourceRef);
  // Now that the backing set is emptied, key1 is released.
  GcFinalization.awaitClear(weakKey1Ref);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:54,代码来源:WeakKeySetTest.java

示例9: testEviction_keyOverlap_3x

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_keyOverlap_3x() {
  TestState state1 = new TestState();
  TestState state2 = new TestState();
  TestState state3 = new TestState();
  Key<Integer> key1 = Key.get(Integer.class);
  Key<Integer> key2 = Key.get(Integer.class);
  Key<Integer> key3 = Key.get(Integer.class);
  Object source1 = new Object();
  Object source2 = new Object();
  Object source3 = new Object();

  set.add(key1, state1, source1);
  assertTrue(set.contains(key1));
  assertEquals(1, set.getSources(key1).size());
  assertTrue(set.getSources(key1).contains(source1));

  set.add(key2, state2, source2);
  assertTrue(set.contains(key2));
  assertEquals(2, set.getSources(key2).size());
  assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));

  set.add(key3, state3, source3);
  assertTrue(set.contains(key3));
  assertEquals(3, set.getSources(key3).size());
  assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2, source3)));

  WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
  WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
  WeakReference<Key<Integer>> weakKey3Ref = new WeakReference<Key<Integer>>(key3);
  WeakReference<Object> weakSource1Ref = new WeakReference<Object>(source1);
  WeakReference<Object> weakSource2Ref = new WeakReference<Object>(source2);
  WeakReference<Object> weakSource3Ref = new WeakReference<Object>(source3);

  Key<Integer> key = key1 = key2 = key3 = Key.get(Integer.class);
  state1 = null;

  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));
  assertEquals(2, set.getSources(key).size());
  assertTrue(set.getSources(key).containsAll(Arrays.asList(source2, source3)));

  source1 = null;
  // Key1 will be referenced as the key in the sources backingSet and won't be
  // GC'd.
  GcFinalization.awaitClear(weakSource1Ref);

  state2 = null;
  GcFinalization.awaitFullGc();

  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source3));

  GcFinalization.awaitClear(weakKey2Ref);
  
  source2 = null;
  GcFinalization.awaitClear(weakSource2Ref);
  // Key1 will be referenced as the key in the sources backingSet and won't be
  // GC'd.

  state3 = null;
  GcFinalization.awaitFullGc();

  assertFalse(set.contains(Key.get(Integer.class)));
  assertNull(set.getSources(Key.get(Integer.class)));

  GcFinalization.awaitClear(weakKey3Ref);
  source3 = null;
  GcFinalization.awaitClear(weakSource3Ref);
  // Now that the backing set is emptied, key1 is released.
  GcFinalization.awaitClear(weakKey1Ref);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:74,代码来源:WeakKeySetTest.java


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