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


Java AtomicReferenceFieldUpdater.set方法代码示例

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


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

示例1: testReferenceFieldUpdaterGetAndUpdate

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater getAndUpdate returns previous value
 * and updates result of supplied function
 */
public void testReferenceFieldUpdaterGetAndUpdate() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals((Integer) 1, a.getAndUpdate(this, Atomic8Test::addInteger17));
    assertEquals((Integer) 18, a.getAndUpdate(this, Atomic8Test::addInteger17));
    assertEquals((Integer) 35, a.get(this));
    assertEquals((Integer) 35, anIntegerField);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例2: testReferenceFieldUpdaterUpdateAndGet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater updateAndGet updates with supplied
 * function and returns result.
 */
public void testReferenceFieldUpdaterUpdateAndGet() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals((Integer) 18, a.updateAndGet(this, Atomic8Test::addInteger17));
    assertEquals((Integer) 35, a.updateAndGet(this, Atomic8Test::addInteger17));
    assertEquals((Integer) 35, a.get(this));
    assertEquals((Integer) 35, anIntegerField);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例3: testReferenceFieldUpdaterGetAndAccumulate

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater returns previous value and updates
 * with supplied function.
 */
public void testReferenceFieldUpdaterGetAndAccumulate() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals((Integer) 1, a.getAndAccumulate(this, 2, Atomic8Test::sumInteger));
    assertEquals((Integer) 3, a.getAndAccumulate(this, 3, Atomic8Test::sumInteger));
    assertEquals((Integer) 6, a.get(this));
    assertEquals((Integer) 6, anIntegerField);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例4: testReferenceFieldUpdaterAccumulateAndGet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater accumulateAndGet updates with
 * supplied function and returns result.
 */
public void testReferenceFieldUpdaterAccumulateAndGet() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals((Integer) 7, a.accumulateAndGet(this, 6, Atomic8Test::sumInteger));
    assertEquals((Integer) 10, a.accumulateAndGet(this, 3, Atomic8Test::sumInteger));
    assertEquals((Integer) 10, a.get(this));
    assertEquals((Integer) 10, anIntegerField);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Atomic8Test.java

示例5: testFieldUpdaters_ClassCastException

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * Object arguments for parameters of type T that are not
 * instances of the class passed to the newUpdater call will
 * result in a ClassCastException being thrown.
 */
public void testFieldUpdaters_ClassCastException() {
    // Use raw types to allow passing wrong object type, provoking CCE
    final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater();
    final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater();
    final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater();
    final Object obj = new Object();
    for (Object x : new Object[]{ new Object(), null }) {
        Runnable[] throwingActions = {
            () -> longUpdater.get(x),
            () -> intUpdater.get(x),
            () -> refUpdater.get(x),

            () -> longUpdater.set(x, 17L),
            () -> intUpdater.set(x, 17),
            () -> refUpdater.set(x, (Integer) 17),

            () -> longUpdater.addAndGet(x, 17L),
            () -> intUpdater.addAndGet(x, 17),

            () -> longUpdater.getAndUpdate(x, y -> y),
            () -> intUpdater.getAndUpdate(x, y -> y),
            () -> refUpdater.getAndUpdate(x, y -> y),

            () -> longUpdater.compareAndSet(x, 17L, 42L),
            () -> intUpdater.compareAndSet(x, 17, 42),
            () -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42),
        };
        assertThrows(ClassCastException.class, throwingActions);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:Atomic8Test.java

示例6: testGetSet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * get returns the last value set or assigned
 */
public void testGetSet() {
    AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
    a = updaterFor("x");
    x = one;
    assertSame(one, a.get(this));
    a.set(this, two);
    assertSame(two, a.get(this));
    a.set(this, m3);
    assertSame(m3, a.get(this));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AtomicReferenceFieldUpdaterTest.java

示例7: testReferenceFieldUpdaterGetAndUpdate

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater getAndUpdate returns previous value
 * and updates result of supplied function
 */
public void testReferenceFieldUpdaterGetAndUpdate() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals(new Integer(1), a.getAndUpdate(this, Atomic8Test::addInteger17));
    assertEquals(new Integer(18), a.getAndUpdate(this, Atomic8Test::addInteger17));
    assertEquals(new Integer(35), a.get(this));
    assertEquals(new Integer(35), anIntegerField);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:13,代码来源:Atomic8Test.java

示例8: testReferenceFieldUpdaterUpdateAndGet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater updateAndGet updates with supplied
 * function and returns result.
 */
public void testReferenceFieldUpdaterUpdateAndGet() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals(new Integer(18), a.updateAndGet(this, Atomic8Test::addInteger17));
    assertEquals(new Integer(35), a.updateAndGet(this, Atomic8Test::addInteger17));
    assertEquals(new Integer(35), a.get(this));
    assertEquals(new Integer(35), anIntegerField);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:13,代码来源:Atomic8Test.java

示例9: testReferenceFieldUpdaterGetAndAccumulate

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater returns previous value and updates
 * with supplied function.
 */
public void testReferenceFieldUpdaterGetAndAccumulate() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals(new Integer(1), a.getAndAccumulate(this, 2, Atomic8Test::sumInteger));
    assertEquals(new Integer(3), a.getAndAccumulate(this, 3, Atomic8Test::sumInteger));
    assertEquals(new Integer(6), a.get(this));
    assertEquals(new Integer(6), anIntegerField);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:13,代码来源:Atomic8Test.java

示例10: testReferenceFieldUpdaterAccumulateAndGet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * AtomicReferenceFieldUpdater accumulateAndGet updates with
 * supplied function and returns result.
 */
public void testReferenceFieldUpdaterAccumulateAndGet() {
    AtomicReferenceFieldUpdater<Atomic8Test,Integer> a = anIntegerFieldUpdater();
    a.set(this, one);
    assertEquals(new Integer(7), a.accumulateAndGet(this, 6, Atomic8Test::sumInteger));
    assertEquals(new Integer(10), a.accumulateAndGet(this, 3, Atomic8Test::sumInteger));
    assertEquals(new Integer(10), a.get(this));
    assertEquals(new Integer(10), anIntegerField);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:13,代码来源:Atomic8Test.java

示例11: DependencyManager

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * Creates a new DependencyManager
 * @param script The script to manage dependencies for
 * @param type The script type
 */
public DependencyManager(final T script, final Class<T> type) {
	this.script = script;
	scriptName = this.script.getClass().getName();
	log = LogManager.getLogger(type);

	cache = GlobalCacheService.getInstance();
	try {
		for(Field f: type.getDeclaredFields()) {
			final Dependency d = f.getAnnotation(Dependency.class);
			if(d!=null) {
				final String cacheKey = d.value().trim();
				depFields.put(cacheKey, f);
				depDefs.put(cacheKey, d);
				f.setAccessible(true);
				final AtomicReferenceFieldUpdater<T, Object> updater =  AtomicReferenceFieldUpdater.newUpdater(type, Object.class, f.getName());
				depUpdaters.put(cacheKey, updater);
				final Object o = cache.getOrNotify(cacheKey, d.type(), this, d.timeout(), d.unit());
				if(o==null) {
					script.addPendingDependency(cacheKey);
				} else {
					log.info("Seting dependent value [{}] on [{}] from cache entry [{}]", o.getClass().getName(), scriptName, cacheKey);
					updater.set(script, o);
					//PrivateAccessor.setFieldValue(script, f.getName(), o);
					cache.addCacheEventListener(this, cacheKey);
					log.info("Dependent value [{}] initialized on [{}] from cache entry [{}]", o.getClass().getName(), scriptName, cacheKey);
				}
			}
		}
	} catch (Exception ex) {
		throw new RuntimeException("Failed to scan script [" + script.sourceReader + "] for dependencies", ex);
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:38,代码来源:DependencyManager.java

示例12: onValueAdded

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.collector.cache.CacheEventListener#onValueAdded(java.lang.String, java.lang.Object)
 */
@Override
public void onValueAdded(final String key, final Object value) {
	final AtomicReferenceFieldUpdater<T, Object> updater = depUpdaters.get(key);
	if(updater!=null) {
		updater.set(script, value);
		script.getBinding().setVariable("_" + depFields.get(key).getName(), value);
		script.removePendingDependency(key);
		log.info("Dependent value [{}] initialized on [{}] from cache entry [{}]", value.getClass().getName(), scriptName, key);
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:15,代码来源:DependencyManager.java

示例13: onValueRemoved

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.collector.cache.CacheEventListener#onValueRemoved(java.lang.String, java.lang.Object)
 */
@Override
public void onValueRemoved(final String key, final Object removedValue) {
	final AtomicReferenceFieldUpdater<T, Object> updater = depUpdaters.get(key);
	if(updater!=null) {
		script.addPendingDependency(key);
		updater.set(script, null);		
		script.getBinding().getVariables().remove("_" + depFields.get(key).getName());
		log.info("Dependent value removed from [{}] based on cleared cache entry [{}]", scriptName, key);
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:15,代码来源:DependencyManager.java

示例14: onValueReplaced

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.collector.cache.CacheEventListener#onValueReplaced(java.lang.String, java.lang.Object, java.lang.Object)
 */
@Override
public void onValueReplaced(final String key, final Object oldValue, final Object newValue) {
	final AtomicReferenceFieldUpdater<T, Object> updater = depUpdaters.get(key);
	if(updater!=null) {
		script.removePendingDependency(key);
		updater.set(script, newValue);
		script.getBinding().setVariable("_" + depFields.get(key).getName() , newValue);
		log.info("Dependent value [{}] replaced on [{}] from cache entry [{}]", newValue.getClass().getName(), scriptName, key);
	}				
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:15,代码来源:DependencyManager.java

示例15: testAtomicReferenceFieldUpdater

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //导入方法依赖的package包/类
static private void testAtomicReferenceFieldUpdater() {
	System.out.println("AtomicTest.testAtomicReferenceFieldUpdater:");
	AtomicTest obj = new AtomicTest();
	AtomicReferenceFieldUpdater<AtomicTest, Integer> updater = AtomicReferenceFieldUpdater.newUpdater(AtomicTest.class, Integer.class, "value");
	System.out.println(updater.get(obj));
	updater.set(obj, 5);
	System.out.println(updater.get(obj));
	updater.compareAndSet(obj, 4, -4);
	System.out.println(updater.get(obj));
	updater.compareAndSet(obj, 5, -5);
	System.out.println(updater.get(obj));
}
 
开发者ID:jtransc,项目名称:jtransc,代码行数:13,代码来源:AtomicTest.java


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