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


Java AtomicLong.set方法代码示例

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


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

示例1: testMaxMapCountCheck

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testMaxMapCountCheck() throws NodeValidationException {
    final int limit = 1 << 18;
    final AtomicLong maxMapCount = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapChecks.MaxMapCountCheck check = new BootstrapChecks.MaxMapCountCheck() {
        @Override
        long getMaxMapCount() {
            return maxMapCount.get();
        }
    };

    final NodeValidationException e = expectThrows(
            NodeValidationException.class,
            () -> BootstrapChecks.check(true, Collections.singletonList(check), "testMaxMapCountCheck"));
    assertThat(e.getMessage(), containsString("max virtual memory areas vm.max_map_count"));

    maxMapCount.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));

    BootstrapChecks.check(true, Collections.singletonList(check), "testMaxMapCountCheck");

    // nothing should happen if current vm.max_map_count is not
    // available
    maxMapCount.set(-1);
    BootstrapChecks.check(true, Collections.singletonList(check), "testMaxMapCountCheck");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:BootstrapCheckTests.java

示例2: discardCachesImpl

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private static void discardCachesImpl(AtomicLong al) {
    File user = Places.getUserDirectory();
    long now = System.currentTimeMillis();
    if (user != null) {
        File f = new File(user, ".lastModified");
        if (f.exists()) {
            f.setLastModified(now);
        } else {
            f.getParentFile().mkdirs();
            try {
                f.createNewFile();
            } catch (IOException ex) {
                LOG.log(Level.WARNING, "Cannot create " + f, ex);
            }
        }
    }
    if (al != null) {
        al.set(now);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Stamps.java

示例3: highestStampForDir

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private static boolean highestStampForDir(File file, AtomicReference<File> newestFile, AtomicLong result, AtomicInteger crc) {
    if (file.getName().equals(".nbattrs")) { // NOI18N
        return true;
    }

    File[] children = file.listFiles();
    if (children == null) {
        if (crc != null) {
            crc.addAndGet(file.getName().length());
        }
        long time = file.lastModified();
        if (time > result.longValue()) {
            newestFile.set(file);
            result.set(time);
        }
        return false;
    }
    
    for (File f : children) {
        highestStampForDir(f, newestFile, result, crc);
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Stamps.java

示例4: testModifying

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void testModifying()
        throws IOException, KeeperException, InterruptedException {
    Stat stat = new Stat();
    zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
    Assert.assertEquals(0, stat.getEphemeralOwner());

    final AtomicLong fakeElapsed = new AtomicLong(0);
    ContainerManager containerManager = newContainerManager(fakeElapsed);
    containerManager.checkContainers();
    Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));

    for ( int i = 0; i < 10; ++i ) {
        fakeElapsed.set(50);
        zk.setData("/foo", new byte[i + 1], -1);
        containerManager.checkContainers();
        Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
    }

    fakeElapsed.set(200);
    containerManager.checkContainers();
    Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:24,代码来源:CreateTTLTest.java

示例5: testPromotion

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testPromotion() {
    AtomicLong now = new AtomicLong();
    Cache<Integer, String> cache = new Cache<Integer, String>() {
        @Override
        protected long now() {
            return now.get();
        }
    };
    cache.setExpireAfterAccessNanos(1);
    now.set(0);
    for (int i = 0; i < numberOfEntries; i++) {
        cache.put(i, Integer.toString(i));
    }
    now.set(1);
    Set<Integer> promotedKeys = new HashSet<>();
    for (int i = 0; i < numberOfEntries; i++) {
        if (rarely()) {
            cache.get(i);
            promotedKeys.add(i);
        }
    }
    now.set(2);
    cache.refresh();
    assertEquals(promotedKeys.size(), cache.count());
    for (int i = 0; i < numberOfEntries; i++) {
        if (promotedKeys.contains(i)) {
            assertNotNull(cache.get(i));
        } else {
            assertNull(cache.get(i));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:CacheTests.java

示例6: waitForChange_emptyDataChange

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
@Test
public void waitForChange_emptyDataChange() throws InterruptedException {
    final CountDownLatch bgRealmOpened = new CountDownLatch(1);
    final CountDownLatch bgRealmClosed = new CountDownLatch(1);
    final AtomicBoolean bgRealmChangeResult = new AtomicBoolean(false);
    final AtomicLong bgRealmWaitForChangeResult = new AtomicLong(0);

    // Waits in background.
    final CountDownLatch signalTestFinished = new CountDownLatch(1);
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            Realm realm = Realm.getInstance(realmConfig);
            bgRealmOpened.countDown();
            bgRealmChangeResult.set(realm.waitForChange());
            bgRealmWaitForChangeResult.set(realm.where(AllTypes.class).count());
            realm.close();
            bgRealmClosed.countDown();
        }
    });
    thread.start();

    TestHelper.awaitOrFail(bgRealmOpened);
    realm.beginTransaction();
    realm.commitTransaction();
    TestHelper.awaitOrFail(bgRealmClosed);
    assertTrue(bgRealmChangeResult.get());
    assertEquals(0, bgRealmWaitForChangeResult.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:RealmTests.java

示例7: testGetSet

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * get returns the last value set
 */
public void testGetSet() {
    AtomicLong ai = new AtomicLong(1);
    assertEquals(1, ai.get());
    ai.set(2);
    assertEquals(2, ai.get());
    ai.set(-3);
    assertEquals(-3, ai.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AtomicLongTest.java

示例8: testFloatValue

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    AtomicLong ai = new AtomicLong();
    assertEquals(0.0f, ai.floatValue());
    for (long x : VALUES) {
        ai.set(x);
        assertEquals((float)x, ai.floatValue());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AtomicLongTest.java

示例9: updateNumberOfWaits

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
private static void updateNumberOfWaits(AtomicLong start, AtomicLong maxTime) {
    Long now = System.currentTimeMillis();
    Long startValue = start.get();
    if (startValue != 0 && now - startValue > 1000) {
        maxTime.incrementAndGet();
    }
    start.set(now);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:9,代码来源:BackpressureIntegrationTest.java

示例10: updatePullFromWhichNode

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void updatePullFromWhichNode(final MessageQueue mq, final long brokerId) {
    AtomicLong suggest = this.pullFromWhichNodeTable.get(mq);
    if (null == suggest) {
        this.pullFromWhichNodeTable.put(mq, new AtomicLong(brokerId));
    }
    else {
        suggest.set(brokerId);
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:10,代码来源:PullAPIWrapper.java

示例11: pollQueue

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
void pollQueue() {
    int emitted = 0;
    AtomicLong localRequested = this.requested;
    AtomicLong localCounter = this.counter;
    do {
        localCounter.set(1);
        long produced = 0;
        long r = localRequested.get();
        while (!this.child.isUnsubscribed()) {
            if (this.finished) {
                Throwable error = this.error;
                if (error != null) {
                    this.queue.clear();
                    this.child.onError(error);
                    return;
                } else if (this.queue.isEmpty()) {
                    this.child.onCompleted();
                    return;
                }
            }
            if (r > 0) {
                Object o = this.queue.poll();
                if (o != null) {
                    this.child.onNext(this.on.getValue(o));
                    r--;
                    emitted++;
                    produced++;
                }
            }
            if (produced > 0 && localRequested.get() != Long.MAX_VALUE) {
                localRequested.addAndGet(-produced);
            }
        }
        return;
    } while (localCounter.decrementAndGet() > 0);
    if (emitted > 0) {
        request((long) emitted);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:40,代码来源:OperatorObserveOn.java

示例12: waitForDocs

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * Waits until at least a give number of document is visible for searchers
 *
 * @param numDocs         number of documents to wait for
 * @param maxWaitTime     if not progress have been made during this time, fail the test
 * @param maxWaitTimeUnit the unit in which maxWaitTime is specified
 * @param indexer         a {@link org.elasticsearch.test.BackgroundIndexer}. If supplied it will be first checked for documents indexed.
 *                        This saves on unneeded searches.
 * @return the actual number of docs seen.
 */
public long waitForDocs(final long numDocs, int maxWaitTime, TimeUnit maxWaitTimeUnit, @Nullable final BackgroundIndexer indexer)
    throws InterruptedException {
    final AtomicLong lastKnownCount = new AtomicLong(-1);
    long lastStartCount = -1;
    BooleanSupplier testDocs = () -> {
        if (indexer != null) {
            lastKnownCount.set(indexer.totalIndexedDocs());
        }
        if (lastKnownCount.get() >= numDocs) {
            try {
                long count = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits();
                if (count == lastKnownCount.get()) {
                    // no progress - try to refresh for the next time
                    client().admin().indices().prepareRefresh().get();
                }
                lastKnownCount.set(count);
            } catch (Exception e) { // count now acts like search and barfs if all shards failed...
                logger.debug("failed to executed count", e);
                return false;
            }
            logger.debug("[{}] docs visible for search. waiting for [{}]", lastKnownCount.get(), numDocs);
        } else {
            logger.debug("[{}] docs indexed. waiting for [{}]", lastKnownCount.get(), numDocs);
        }
        return lastKnownCount.get() >= numDocs;
    };

    while (!awaitBusy(testDocs, maxWaitTime, maxWaitTimeUnit)) {
        if (lastStartCount == lastKnownCount.get()) {
            // we didn't make any progress
            fail("failed to reach " + numDocs + "docs");
        }
        lastStartCount = lastKnownCount.get();
    }
    return lastKnownCount.get();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:ESIntegTestCase.java

示例13: testFileDescriptorLimits

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testFileDescriptorLimits() throws NodeValidationException {
    final boolean osX = randomBoolean(); // simulates OS X versus non-OS X
    final int limit = osX ? 10240 : 1 << 16;
    final AtomicLong maxFileDescriptorCount = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapChecks.FileDescriptorCheck check;
    if (osX) {
        check = new BootstrapChecks.OsXFileDescriptorCheck() {
            @Override
            long getMaxFileDescriptorCount() {
                return maxFileDescriptorCount.get();
            }
        };
    } else {
        check = new BootstrapChecks.FileDescriptorCheck() {
            @Override
            long getMaxFileDescriptorCount() {
                return maxFileDescriptorCount.get();
            }
        };
    }

    final NodeValidationException e =
            expectThrows(NodeValidationException.class,
                    () -> BootstrapChecks.check(true, Collections.singletonList(check), "testFileDescriptorLimits"));
    assertThat(e.getMessage(), containsString("max file descriptors"));

    maxFileDescriptorCount.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));

    BootstrapChecks.check(true, Collections.singletonList(check), "testFileDescriptorLimits");

    // nothing should happen if current file descriptor count is
    // not available
    maxFileDescriptorCount.set(-1);
    BootstrapChecks.check(true, Collections.singletonList(check), "testFileDescriptorLimits");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:BootstrapCheckTests.java

示例14: testExpirationAfterAccess

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
public void testExpirationAfterAccess() {
    AtomicLong now = new AtomicLong();
    Cache<Integer, String> cache = new Cache<Integer, String>() {
        @Override
        protected long now() {
            return now.get();
        }
    };
    cache.setExpireAfterAccessNanos(1);
    List<Integer> evictedKeys = new ArrayList<>();
    cache.setRemovalListener(notification -> {
        assertEquals(RemovalNotification.RemovalReason.EVICTED, notification.getRemovalReason());
        evictedKeys.add(notification.getKey());
    });
    now.set(0);
    for (int i = 0; i < numberOfEntries; i++) {
        cache.put(i, Integer.toString(i));
    }
    now.set(1);
    for (int i = numberOfEntries; i < 2 * numberOfEntries; i++) {
        cache.put(i, Integer.toString(i));
    }
    now.set(2);
    cache.refresh();
    assertEquals(numberOfEntries, cache.count());
    for (int i = 0; i < evictedKeys.size(); i++) {
        assertEquals(i, (int) evictedKeys.get(i));
    }
    Set<Integer> remainingKeys = new HashSet<>();
    for (Integer key : cache.keys()) {
        remainingKeys.add(key);
    }
    for (int i = numberOfEntries; i < 2 * numberOfEntries; i++) {
        assertTrue(remainingKeys.contains(i));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:CacheTests.java

示例15: conditionalShow

import java.util.concurrent.atomic.AtomicLong; //导入方法依赖的package包/类
/**
 * @return true if we actually showed, false if we just called toFront()
 */
private boolean conditionalShow(Component toFocus, AtomicLong time) {
    boolean retval;

    closeSplashScreen();

    synchronized (getTreeLock()) {
        if (peer == null) {
            addNotify();
        }
        validateUnconditionally();
        if (visible) {
            toFront();
            retval = false;
        } else {
            visible = retval = true;

            // check if this dialog should be modal blocked BEFORE calling peer.show(),
            // otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly
            // generated for the dialog
            if (!isModal()) {
                checkShouldBeBlocked(this);
            } else {
                modalDialogs.add(this);
                modalShow();
            }

            if (toFocus != null && time != null && isFocusable() &&
                isEnabled() && !isModalBlocked()) {
                // keep the KeyEvents from being dispatched
                // until the focus has been transfered
                time.set(Toolkit.getEventQueue().getMostRecentKeyEventTime());
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
                    enqueueKeyEvents(time.get(), toFocus);
            }

            // This call is required as the show() method of the Dialog class
            // does not invoke the super.show(). So wried... :(
            mixOnShowing();

            peer.setVisible(true); // now guaranteed never to block
            if (isModalBlocked()) {
                modalBlocker.toFront();
            }

            setLocationByPlatform(false);
            for (int i = 0; i < ownedWindowList.size(); i++) {
                Window child = ownedWindowList.elementAt(i).get();
                if ((child != null) && child.showWithParent) {
                    child.show();
                    child.showWithParent = false;
                }       // endif
            }   // endfor
            Window.updateChildFocusableWindowState(this);

            createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
                                  this, parent,
                                  HierarchyEvent.SHOWING_CHANGED,
                                  Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
            if (componentListener != null ||
                    (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
                    Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
                ComponentEvent e =
                    new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
                Toolkit.getEventQueue().postEvent(e);
            }
        }
    }

    if (retval && (state & OPENED) == 0) {
        postWindowEvent(WindowEvent.WINDOW_OPENED);
        state |= OPENED;
    }

    return retval;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:79,代码来源:Dialog.java


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