• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java WaitQueue类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.cassandra.utils.concurrent.WaitQueue的典型用法代码示例。如果您正苦于以下问题:Java WaitQueue类的具体用法?Java WaitQueue怎么用?Java WaitQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

WaitQueue类属于org.apache.cassandra.utils.concurrent包,在下文中一共展示了WaitQueue类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
@Override
public void run()
{
    while (true)
    {
        while (!needsCleaning())
        {
            final WaitQueue.Signal signal = wait.register();
            if (!needsCleaning())
                signal.awaitUninterruptibly();
            else
                signal.cancel();
        }

        cleaner.run();
    }
}
 

开发者ID:Netflix,
项目名称:sstable-adaptor,
代码行数:18,
代码来源:MemtableCleanerThread.java

示例2: allocate

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
public void allocate(long size, OpOrder.Group opGroup)
{
    while (true)
    {
        if (parent.tryAllocate(size))
        {
            acquired(size);
            return;
        }
        WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register());
        boolean allocated = parent.tryAllocate(size);
        if (allocated || opGroup.isBlocking())
        {
            signal.cancel();
            if (allocated) // if we allocated, take ownership
                acquired(size);
            else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking
                allocated(size);
            return;
        }
        else
            signal.awaitUninterruptibly();
    }
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:25,
代码来源:MemtableAllocator.java

示例3: maybeWaitForSync

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
protected void maybeWaitForSync(CommitLogSegment.Allocation alloc)
{
    if (waitForSyncToCatchUp(Long.MAX_VALUE))
    {
        // wait until periodic sync() catches up with its schedule
        long started = System.currentTimeMillis();
        pending.incrementAndGet();
        while (waitForSyncToCatchUp(started))
        {
            WaitQueue.Signal signal = syncComplete.register(CommitLog.instance.metrics.waitingOnCommit.time());
            if (waitForSyncToCatchUp(started))
                signal.awaitUninterruptibly();
            else
                signal.cancel();
        }
        pending.decrementAndGet();
    }
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:19,
代码来源:PeriodicCommitLogService.java

示例4: waitForFinalSync

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
void waitForFinalSync()
{
    while (true)
    {
        WaitQueue.Signal signal = syncComplete.register();
        if (lastSyncedOffset < buffer.capacity())
        {
            signal.awaitUninterruptibly();
        }
        else
        {
            signal.cancel();
            break;
        }
    }
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:17,
代码来源:CommitLogSegment.java

示例5: maybeWaitForSync

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
protected void maybeWaitForSync(CommitLogSegment.Allocation alloc)
{
    if (waitForSyncToCatchUp(Long.MAX_VALUE))
    {
        // wait until periodic sync() catches up with its schedule
        long started = System.currentTimeMillis();
        pending.incrementAndGet();
        while (waitForSyncToCatchUp(started))
        {
            WaitQueue.Signal signal = syncComplete.register(commitLog.metrics.waitingOnCommit.time());
            if (waitForSyncToCatchUp(started))
                signal.awaitUninterruptibly();
            else
                signal.cancel();
        }
        pending.decrementAndGet();
    }
}
 

开发者ID:scylladb,
项目名称:scylla-tools-java
代码行数:19,
代码来源:PeriodicCommitLogService.java

示例6: waitForFinalSync

点赞 3

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
void waitForFinalSync()
{
    while (true)
    {
        WaitQueue.Signal signal = syncComplete.register();
        if (lastSyncedOffset < endOfBuffer)
        {
            signal.awaitUninterruptibly();
        }
        else
        {
            signal.cancel();
            break;
        }
    }
}
 

开发者ID:scylladb,
项目名称:scylla-tools-java
代码行数:17,
代码来源:CommitLogSegment.java

示例7: requestExtraSync

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
/**
 * Sync immediately, but don't block for the sync to cmplete
 */
public WaitQueue.Signal requestExtraSync()
{
    WaitQueue.Signal signal = syncComplete.register();
    haveWork.release(1);
    return signal;
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:10,
代码来源:AbstractCommitLogService.java

示例8: awaitDiskSync

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
void awaitDiskSync()
{
    while (segment.lastSyncedOffset < position)
    {
        WaitQueue.Signal signal = segment.syncComplete.register(CommitLog.instance.metrics.waitingOnCommit.time());
        if (segment.lastSyncedOffset < position)
            signal.awaitUninterruptibly();
        else
            signal.cancel();
    }
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:12,
代码来源:CommitLogSegment.java

示例9: testSerial

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
public void testSerial(final WaitQueue queue) throws InterruptedException
{
    Thread[] ts = new Thread[4];
    for (int i = 0 ; i < ts.length ; i++)
        ts[i] = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            WaitQueue.Signal wait = queue.register();
            try
            {
                wait.await();
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    });
    for (int i = 0 ; i < ts.length ; i++)
        ts[i].start();
    Thread.sleep(100);
    queue.signal();
    queue.signal();
    queue.signal();
    queue.signal();
    for (int i = 0 ; i < ts.length ; i++)
    {
        ts[i].join(100);
        assertFalse(queue.getClass().getName(), ts[i].isAlive());
    }
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:33,
代码来源:WaitQueueTest.java

示例10: testCondition1

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
public void testCondition1(final WaitQueue queue) throws InterruptedException
{
    final AtomicBoolean cond1 = new AtomicBoolean(false);
    final AtomicBoolean fail = new AtomicBoolean(false);
    Thread t1 = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                Thread.sleep(200);
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            WaitQueue.Signal wait = queue.register();
            if (!cond1.get())
            {
                System.err.println("Condition should have already been met");
                fail.set(true);
            }
        }
    });
    t1.start();
    Thread.sleep(50);
    cond1.set(true);
    Thread.sleep(300);
    queue.signal();
    t1.join(300);
    assertFalse(queue.getClass().getName(), t1.isAlive());
    assertFalse(fail.get());
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:34,
代码来源:WaitQueueTest.java

示例11: testCondition2

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
public void testCondition2(final WaitQueue queue) throws InterruptedException
{
    final AtomicBoolean condition = new AtomicBoolean(false);
    final AtomicBoolean fail = new AtomicBoolean(false);
    Thread t = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            WaitQueue.Signal wait = queue.register();
            if (condition.get())
            {
                System.err.println("");
                fail.set(true);
            }

            try
            {
                Thread.sleep(200);
                wait.await();
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            if (!condition.get())
            {
                System.err.println("Woke up when condition not met");
                fail.set(true);
            }
        }
    });
    t.start();
    Thread.sleep(50);
    condition.set(true);
    queue.signal();
    t.join(300);
    assertFalse(queue.getClass().getName(), t.isAlive());
    assertFalse(fail.get());
}
 

开发者ID:vcostet,
项目名称:cassandra-kmean,
代码行数:40,
代码来源:WaitQueueTest.java

示例12: waitForSync

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
void waitForSync(int position, Timer waitingOnCommit)
{
    while (lastSyncedOffset < position)
    {
        WaitQueue.Signal signal = waitingOnCommit != null ?
                                  syncComplete.register(waitingOnCommit.time()) :
                                  syncComplete.register();
        if (lastSyncedOffset < position)
            signal.awaitUninterruptibly();
        else
            signal.cancel();
    }
}
 

开发者ID:scylladb,
项目名称:scylla-tools-java
代码行数:14,
代码来源:CommitLogSegment.java

示例13: testCondition

点赞 2

import org.apache.cassandra.utils.concurrent.WaitQueue; //导入依赖的package包/类
public void testCondition(final WaitQueue queue) throws InterruptedException
{
    final AtomicBoolean ready = new AtomicBoolean(false);
    final AtomicBoolean condition = new AtomicBoolean(false);
    final AtomicBoolean fail = new AtomicBoolean(false);
    Thread t = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            WaitQueue.Signal wait = queue.register();
            if (condition.get())
            {
                System.err.println("");
                fail.set(true);
                ready.set(true);
                return;
            }

            ready.set(true);
            wait.awaitUninterruptibly();
            if (!condition.get())
            {
                System.err.println("Woke up when condition not met");
                fail.set(true);
            }
        }
    });
    t.start();
    final ThreadLocalRandom random = ThreadLocalRandom.current();
    while (!ready.get())
        random.nextLong();
    condition.set(true);
    queue.signal();
    Util.joinThread(t);
    assertFalse(queue.getClass().getName(), t.isAlive());
    assertFalse(fail.get());
}
 

开发者ID:scylladb,
项目名称:scylla-tools-java
代码行数:39,
代码来源:WaitQueueTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)