Java Code Examples for java.util.concurrent.atomic.AtomicLong.getAndAdd()

The following are Jave code examples for showing how to use getAndAdd() of the java.util.concurrent.atomic.AtomicLong class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: CacheUtils.java   Source Code and License Vote up 6 votes
private CacheManager(final File cacheDir, final long sizeLimit, final int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    mThread = new Thread(new Runnable() {
        @Override
        public void run() {
            int size = 0;
            int count = 0;
            final File[] cachedFiles = cacheDir.listFiles();
            if (cachedFiles != null) {
                for (File cachedFile : cachedFiles) {
                    size += cachedFile.length();
                    count += 1;
                    lastUsageDates.put(cachedFile, cachedFile.lastModified());
                }
                cacheSize.getAndAdd(size);
                cacheCount.getAndAdd(count);
            }
        }
    });
    mThread.start();
}
 
Example 2
Project: OpenJSharp   File: ForkJoinPool.java   Source Code and License Vote up 5 votes
/**
 * Adds steal count to pool stealCounter if it exists, and resets.
 */
final void transferStealCount(ForkJoinPool p) {
    AtomicLong sc;
    if (p != null && (sc = p.stealCounter) != null) {
        int s = nsteals;
        nsteals = 0;            // if negative, correct for overflow
        sc.getAndAdd((long)(s < 0 ? Integer.MAX_VALUE : s));
    }
}
 
Example 3
Project: jdk8u-jdk   File: ForkJoinPool.java   Source Code and License Vote up 5 votes
/**
 * Adds steal count to pool stealCounter if it exists, and resets.
 */
final void transferStealCount(ForkJoinPool p) {
    AtomicLong sc;
    if (p != null && (sc = p.stealCounter) != null) {
        int s = nsteals;
        nsteals = 0;            // if negative, correct for overflow
        sc.getAndAdd((long)(s < 0 ? Integer.MAX_VALUE : s));
    }
}