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


Java Condition类代码示例

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


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

示例1: get

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public T get(int index, Condition<? super T> condition) {
    T result = null;
    locks.get(index).lock();
    try {
        while (!condition.satisfy(result = list.get(index))) {
            conditions.get(index).await();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        locks.get(index).unlock();
    }
    return result;
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:15,代码来源:AugmentedListCanary.java

示例2: wait

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void wait(int index, Condition<? super T> condition) {
    locks.get(index).lock();
    try {
        while (!condition.satisfy(list.get(index))) {
            conditions.get(index).await();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        locks.get(index).unlock();
    }
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:13,代码来源:AugmentedListCanary.java

示例3: actionNonBlocking

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void actionNonBlocking(final Action<? super T> action, final Condition<? super T> condition) {
    if (condition == null) {
        throw new IllegalArgumentException("Condition cannot be null.");
    }
    lock.lock();
    if (condition.satisfy(object)) {
        action.call(object);
    } else {
        if (!waitingActions.containsKey(condition)) {
            waitingActions.put(condition, new ConcurrentLinkedQueue<Action<? super T>>());
            EXECUTOR.execute(new Runnable() {
                @Override
                public void run() {
                    ConcurrentLinkedQueue<Action<? super T>> q = waitingActions.get(condition);
                    try {
                        lock.lock();
                        while (!condition.satisfy(object)) {
                            ObjectCanary.this.condition.await();
                        }
                        Action<? super T> tmpAction;
                        while ((tmpAction = q.poll()) != null) {
                            tmpAction.call(object);
                        }
                        waitingActions.remove(condition);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                        lock.unlock();
                    }
                }
            });
        }
        waitingActions.get(condition).offer(action);
    }
    lock.unlock();
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:37,代码来源:ObjectCanary.java

示例4: performFunctionUnderCondition

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
private <R> R performFunctionUnderCondition( Function<? super T, ? extends R> function, Condition<? super T> condition, boolean signal) {
    R result = null;
    try {
        lock.lock();
        while (condition != null && !condition.satisfy(object)) {
            if (Config.DEBUG) {
                System.out.println(Thread.currentThread().getName() + " before await");
            }
            this.condition.await();
            if (Config.DEBUG) {
                System.out.println(Thread.currentThread().getName() + " after await");
            }
        }
        if (function != null) {
            result = function.call(object);
        }
        if (signal) {
            if (Config.DEBUG) {
                System.out.println(Thread.currentThread().getName() + " signal");
            }
            //will signal all, but only one can go on.
            this.condition.signalAll();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        lock.unlock();
    }
    return result;
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:31,代码来源:ObjectCanary.java

示例5: waitForInput

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void waitForInput() {
    int waitingIndex = mWaiting - 1;
    mPlayer.getInputs().wait(waitingIndex, new Condition<PlayerInputs>() {
        @Override
        public boolean satisfy(PlayerInputs o) {
            return o.getFinishedNumber().get() == o.getFunctionNumber();
        }
    });
}
 
开发者ID:elemers,项目名称:ToyRoom,代码行数:10,代码来源:ScheduledRunnable.java

示例6: inputSet

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean inputSet() {
    return mPlayer.getInputs().satisfy(mWaiting - 1, new Condition<PlayerInputs>() {
        @Override
        public boolean satisfy(PlayerInputs o) {
            return o.getFinishedNumber().get() == o.getFunctionNumber();
        }
    });
}
 
开发者ID:elemers,项目名称:ToyRoom,代码行数:9,代码来源:ScheduledRunnable.java

示例7: waitForFinishing

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public final CopyOnWriteArrayList<Object> waitForFinishing() {
    int index = mInputs.size() - 1;
    return mInputs.get(index, new Condition<PlayerInputs>() {
        @Override
        public boolean satisfy(PlayerInputs o) {
            return o.getFinishedNumber().get() == o.getFunctionNumber();
        }
    }).getInputs();
}
 
开发者ID:elemers,项目名称:ToyRoom,代码行数:10,代码来源:Player.java

示例8: AugmentedListCanary

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public AugmentedListCanary() {
    list = new CopyOnWriteArrayList<T>();
    locks = new CopyOnWriteArrayList<Lock>();
    conditions = new CopyOnWriteArrayList<java.util.concurrent.locks.Condition>();
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:6,代码来源:AugmentedListCanary.java

示例9: satisfy

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean satisfy(int index, Condition<? super T> condition) {
    locks.get(index).lock();
    boolean result = condition.satisfy(list.get(index));
    locks.get(index).unlock();
    return result;
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:7,代码来源:AugmentedListCanary.java

示例10: ObjectCanary

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public <R extends T> ObjectCanary(R object) {
    this.object = object;
    lock = new ReentrantLock();
    condition = lock.newCondition();
    waitingActions = new ConcurrentHashMap<Condition<? super T>, ConcurrentLinkedQueue<Action<? super T>>>();
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:7,代码来源:ObjectCanary.java

示例11: calculate

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public <R> R calculate(Function<? super T, ? extends R> function, Condition<? super T> condition) {
    return performFunctionUnderCondition(function, condition, false);
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:4,代码来源:ObjectCanary.java

示例12: wait

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void wait(Condition<? super T> condition) {
    performFunctionUnderCondition(null, condition, false);
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:4,代码来源:ObjectCanary.java

示例13: satisfy

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean satisfy(Condition<? super T> condition) {
    lock.lock();
    boolean result = condition.satisfy(object);
    lock.unlock();
    return result;
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:7,代码来源:ObjectCanary.java

示例14: get

import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public T get(Condition<? super T> condition) {
    return performFunctionUnderCondition(identicalFunction, condition, false);
}
 
开发者ID:Xiaofei-it,项目名称:Concurrent-Utils,代码行数:4,代码来源:ObjectCanary.java


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