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


Java AtomicLongFieldUpdater.newUpdater方法代码示例

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


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

示例1: checkPrivateAccess

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
public void checkPrivateAccess() {
    try {
        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
            AtomicLongFieldUpdater.newUpdater
            (AtomicLongFieldUpdaterTest.class, "privateField");
        shouldThrow();
    } catch (RuntimeException success) {
        assertNotNull(success.getCause());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:AtomicLongFieldUpdaterTest.java

示例2: checkCompareAndSetProtectedSub

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
public void checkCompareAndSetProtectedSub() {
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
        AtomicLongFieldUpdater.newUpdater
        (AtomicLongFieldUpdaterTest.class, "protectedField");
    this.protectedField = 1;
    assertTrue(a.compareAndSet(this, 1, 2));
    assertTrue(a.compareAndSet(this, 2, -4));
    assertEquals(-4, a.get(this));
    assertFalse(a.compareAndSet(this, -5, 7));
    assertEquals(-4, a.get(this));
    assertTrue(a.compareAndSet(this, -4, 7));
    assertEquals(7, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AtomicLongFieldUpdaterTest.java

示例3: checkPackageAccess

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
public void checkPackageAccess(AtomicLongFieldUpdaterTest obj) {
    obj.x = 72L;
    AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
        AtomicLongFieldUpdater.newUpdater
        (AtomicLongFieldUpdaterTest.class, "x");
    assertEquals(72L, a.get(obj));
    assertTrue(a.compareAndSet(obj, 72L, 73L));
    assertEquals(73L, a.get(obj));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:AtomicLongFieldUpdaterTest.java

示例4: SW_testCompareAtomicOps

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/** compare raw numbers for atomic ops using JDK vs unsafe wrapper classes */
public void SW_testCompareAtomicOps() {

  final AtomicIntegerFieldUpdater<ConcurrentMapOpsTest> intJDKCounter =
      AtomicIntegerFieldUpdater.newUpdater(ConcurrentMapOpsTest.class,
          "intJDKCounter");
  final AtomicLongFieldUpdater<ConcurrentMapOpsTest> longJDKCounter =
      AtomicLongFieldUpdater.newUpdater(ConcurrentMapOpsTest.class,
          "longJDKCounter");
  final AtomicReferenceFieldUpdater<ConcurrentMapOpsTest, LongRef>
      refJDKCounter = AtomicReferenceFieldUpdater.newUpdater(
          ConcurrentMapOpsTest.class, LongRef.class, "refJDKCounter");

  final AtomicIntegerFieldUpdater<ConcurrentMapOpsTest> intUnsafeCounter =
      AtomicUpdaterFactory.newIntegerFieldUpdater(ConcurrentMapOpsTest.class,
          "intUnsafeCounter");
  final AtomicLongFieldUpdater<ConcurrentMapOpsTest> longUnsafeCounter =
      AtomicUpdaterFactory.newLongFieldUpdater(ConcurrentMapOpsTest.class,
          "longUnsafeCounter");
  final AtomicReferenceFieldUpdater<ConcurrentMapOpsTest, LongRef>
      refUnsafeCounter = AtomicUpdaterFactory.newReferenceFieldUpdater(
          ConcurrentMapOpsTest.class, LongRef.class, "refUnsafeCounter");

  // some warmups
  runAtomicOps(1, 50000, intJDKCounter, longJDKCounter, refJDKCounter,
      intUnsafeCounter, longUnsafeCounter, refUnsafeCounter);

  // timed runs with single threads to see the raw overheads with no
  // concurrency (as we would expect in most usual cases)
  runAtomicOps(1, 50000000, intJDKCounter, longJDKCounter, refJDKCounter,
      intUnsafeCounter, longUnsafeCounter, refUnsafeCounter);

  // now with concurrency
  runAtomicOps(5, 2000000, intJDKCounter, longJDKCounter, refJDKCounter,
      intUnsafeCounter, longUnsafeCounter, refUnsafeCounter);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:37,代码来源:ConcurrentMapOpsTest.java

示例5: newLongFieldUpdater

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * Creates and returns an updater for objects with the given long field.
 */
public static <T> AtomicLongFieldUpdater<T> newLongFieldUpdater(
    Class<T> tclass, String fieldName) {
  if (hasLongCAS && UnsafeHolder.hasUnsafe()) {
    return new UnsafeAtomicLongFieldUpdater<T>(tclass, fieldName);
  }
  else {
    return AtomicLongFieldUpdater.newUpdater(tclass, fieldName);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:13,代码来源:AtomicUpdaterFactory.java

示例6: reset

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
public void reset() {
    this.maxRequestTimeUpdater = AtomicIntegerFieldUpdater.newUpdater(Metrics.class, "maxRequestTime");
    this.minRequestTimeUpdater = AtomicIntegerFieldUpdater.newUpdater(Metrics.class, "minRequestTime");
    this.totalRequestTimeUpdater = AtomicLongFieldUpdater.newUpdater(Metrics.class, "totalRequestTime");
    this.totalRequestsUpdater = AtomicLongFieldUpdater.newUpdater(Metrics.class, "totalRequests");
    this.responseCount = new ConcurrentHashMap<>(INITIAL_CAPACITY, LOAD_FACTOR, CONCURRENCY_LEVEL);
    this.dataSend = new AtomicLong();
    this.avgRequestTime = 0;
    this.totalRequestTime = 0;
    this.totalRequests = 0;
    this.maxRequestTime = 0;
    this.minRequestTime = 0;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:14,代码来源:Metrics.java

示例7: should_create_error_message_for_AtomicLongFieldUpdater

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
@Test
public void should_create_error_message_for_AtomicLongFieldUpdater() {
  // GIVEN
  AtomicLongFieldUpdater<Person> updater = AtomicLongFieldUpdater.newUpdater(Person.class, "account");
  // WHEN
  String message = shouldHaveValue(updater, 123456789L, 0L, joe).create(TEST_DESCRIPTION, CONFIGURATION_PROVIDER.representation());
  // THEN
  assertThat(message).isEqualTo(format("[TEST] %n" +
                                       "Expecting <AtomicLongFieldUpdater> to have value:%n" +
                                       "  <0L>%n" +
                                       "but had:%n" +
                                       "  <123456789L>%n" +
                                       "to update target object:%n" +
                                       "  <Person [name=Joe, age=33, account=123456789]>"));
}
 
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:16,代码来源:ShouldHaveValue_create_Test.java

示例8: should_fail_if_expected_value_is_null_and_does_not_contain_expected_value

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
@Test
public void should_fail_if_expected_value_is_null_and_does_not_contain_expected_value() throws Exception {
  AtomicLongFieldUpdater<Person> fieldUpdater = AtomicLongFieldUpdater.newUpdater(Person.class, "age");
  thrown.expectIllegalArgumentException("The expected value should not be <null>.");

  assertThat(fieldUpdater).hasValue(null, person);
}
 
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:8,代码来源:AtomicLongFieldUpdater_hasValue_Test.java

示例9: should_fail_if_atomicLongFieldUpdater_does_not_contain_expected_value

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
@Test
public void should_fail_if_atomicLongFieldUpdater_does_not_contain_expected_value() throws Exception {
  AtomicLongFieldUpdater<Person> fieldUpdater = AtomicLongFieldUpdater.newUpdater(Person.class, "age");

  thrown.expectAssertionError(shouldHaveValue(fieldUpdater, person.age, 25L, person).create());

  assertThat(fieldUpdater).hasValue(25L, person);
}
 
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:9,代码来源:AtomicLongFieldUpdater_hasValue_Test.java

示例10: keep7

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
void keep7() throws SecurityException {
  AtomicLongFieldUpdater.newUpdater(Reflect2.class, "fieldLong");
  AtomicLongFieldUpdater.newUpdater(Reflect2.class, "fieldLong2");
}
 
开发者ID:inferjay,项目名称:r8,代码行数:5,代码来源:Reflect.java

示例11: testAPI

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
/**
 * Basic tests of the API : Simple function calls to exercise all of the functions listed in the API
 * specification for the AtomicLongFieldUpdater class.
 */	
public void testAPI()
{
	// =================================================================================
	// Create instances of AtomicLongFieldUpdater to work with
	
	for(int i = 0; i < updaters.length; i++)
	{
		updaters[i] = AtomicLongFieldUpdater.newUpdater(AtomicTestObject.class, "volatileLong");
	}

	// =================================================================================
	// Constructors
	
	assertEquals("1 : get()", 42, getRandomUpdater().get(testObject1));
	assertEquals("2 : get()", getRandomUpdater().get(testObject1), getRandomUpdater().get(testObject2));
	assertEquals("3 : get()", getRandomUpdater().get(testObject1), getRandomUpdater().get(testObject1));
	assertEquals("4 : get()", getRandomUpdater().get(testObject2), getRandomUpdater().get(testObject2));
	
	assertEquals("5 : addAndGet()", 43, getRandomUpdater().addAndGet(testObject1, 1));
	assertEquals("6 : get() addAndGet()", getRandomUpdater().get(testObject1), getRandomUpdater().addAndGet(testObject2, 1));
	assertEquals("7 : addAndGet()", 0, getRandomUpdater().addAndGet(testObject1, -43));
	assertEquals("8 : addAndGet() get()", 43, getRandomUpdater().addAndGet(testObject1, getRandomUpdater().get(testObject2)));
	assertEquals("9 : getAndAdd()", 43, getRandomUpdater().getAndAdd(testObject2, 43));
	assertEquals("10 : addAndGet()", 43, getRandomUpdater().addAndGet(testObject2, -43));
	assertEquals("11 : getAndAdd() addAndGet()", getRandomUpdater().getAndAdd(testObject2, 0), getRandomUpdater().addAndGet(testObject2, 0));
	assertEquals("12 : addAndGet() getAndAdd()", getRandomUpdater().addAndGet(testObject1, Long.MAX_VALUE), getRandomUpdater().getAndAdd(testObject2, 0) + Long.MAX_VALUE);
	assertEquals("13 : addAndGet() getAndAdd()", getRandomUpdater().addAndGet(testObject1, -Long.MAX_VALUE), getRandomUpdater().getAndAdd(testObject2, 0));
	
	assertEquals("14 : decrementAndGet()", 42, getRandomUpdater().decrementAndGet(testObject1));
	assertEquals("15 : get() decrementAndGet()", getRandomUpdater().get(testObject1), getRandomUpdater().decrementAndGet(testObject2));
	assertEquals("16 : getAndDecrement() incrementAndGet()", getRandomUpdater().getAndDecrement(testObject1), getRandomUpdater().incrementAndGet(testObject1));
	assertEquals("17 : decrementAndGet() getAndIncrement()", getRandomUpdater().decrementAndGet(testObject2), getRandomUpdater().getAndIncrement(testObject2));
	
	getRandomUpdater().set(testObject1, Long.MIN_VALUE);
	assertEquals("18 : set() get()", Long.MIN_VALUE, getRandomUpdater().get(testObject1));
	assertEquals("19 : decrementAndGet()", Long.MAX_VALUE, getRandomUpdater().decrementAndGet(testObject1));
	getRandomUpdater().set(testObject1, 42);
	assertEquals("20 : set() get()", 42, getRandomUpdater().get(testObject2));
	
	getRandomUpdater().set(testObject1, Long.MAX_VALUE);
	assertEquals("21 : set() get()", Long.MAX_VALUE, getRandomUpdater().get(testObject1));
	assertEquals("22 : incrementAndGet()", Long.MIN_VALUE, getRandomUpdater().incrementAndGet(testObject1));
	getRandomUpdater().set(testObject1, 42);
	assertEquals("23 : set() get()", 42, getRandomUpdater().get(testObject2));
	
	assertEquals("24 : compareAndSet()", true, getRandomUpdater().compareAndSet(testObject1, 42, Long.MAX_VALUE));
	assertEquals("25 : compareAndSet()", true, getRandomUpdater().compareAndSet(testObject1, Long.MAX_VALUE, 42));
	assertEquals("26 : compareAndSet()", false, getRandomUpdater().compareAndSet(testObject1, 0, 42));
	
	assertEquals("27 : compareAndSet()", true, getRandomUpdater().compareAndSet(testObject2, 42, Long.MIN_VALUE));
	assertEquals("28 : compareAndSet()", true, getRandomUpdater().compareAndSet(testObject2, Long.MIN_VALUE, 42));
	assertEquals("29 : compareAndSet()", false, getRandomUpdater().compareAndSet(testObject2, 0, 42));

	assertEquals("30 : get() get()", getRandomUpdater().get(testObject1) == 42, getRandomUpdater().get(testObject2) == 42);
	assertEquals("31 : compareAndSet() get() incrementAndGet()", true, getRandomUpdater().compareAndSet(testObject1, getRandomUpdater().get(testObject1), getRandomUpdater().incrementAndGet(testObject2)));
	assertEquals("32 : get() get()", getRandomUpdater().get(testObject1), getRandomUpdater().get(testObject2));
	assertEquals("33 : getAndDecrement() incrementAndGet()", getRandomUpdater().getAndDecrement(testObject1), getRandomUpdater().incrementAndGet(testObject1));
	assertEquals("34 : andAndGet() get() addAndGet() get()", getRandomUpdater().addAndGet(testObject1, getRandomUpdater().get(testObject1)), getRandomUpdater().addAndGet(testObject2, getRandomUpdater().get(testObject2)));
	assertEquals("35 : compareAndSet() get()", true, getRandomUpdater().compareAndSet(testObject1, getRandomUpdater().get(testObject1), 42));
	assertEquals("36 : compareAndSet() get()", true, getRandomUpdater().compareAndSet(testObject2, getRandomUpdater().get(testObject2), 42));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:66,代码来源:AtomicLongFieldUpdaterTest.java

示例12: updaterFor

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> updaterFor(String fieldName) {
    return AtomicLongFieldUpdater.newUpdater
        (AtomicLongFieldUpdaterTest.class, fieldName);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:AtomicLongFieldUpdaterTest.java

示例13: aLongFieldUpdater

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
AtomicLongFieldUpdater<Atomic8Test> aLongFieldUpdater() {
    return AtomicLongFieldUpdater.newUpdater
        (Atomic8Test.class, "aLongField");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:Atomic8Test.java

示例14: aLongFieldUpdater

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
AtomicLongFieldUpdater aLongFieldUpdater() {
    return AtomicLongFieldUpdater.newUpdater
        (Atomic8Test.class, "aLongField");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:5,代码来源:Atomic8Test.java

示例15: should_pass_if_atomicLongFieldUpdater_contains_expected_value

import java.util.concurrent.atomic.AtomicLongFieldUpdater; //导入方法依赖的package包/类
@Test
public void should_pass_if_atomicLongFieldUpdater_contains_expected_value() throws Exception {
  AtomicLongFieldUpdater<Person> fieldUpdater = AtomicLongFieldUpdater.newUpdater(Person.class, "age");
  fieldUpdater.set(person, 25);
  assertThat(fieldUpdater).hasValue(25L, person);
}
 
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:7,代码来源:AtomicLongFieldUpdater_hasValue_Test.java


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