Java 类java.util.concurrent.Delayed 实例源码
项目:JavaCommon
文件:Cache.java
@Override
public int compareTo(Delayed o) {
if (o == null)
return 1;
if (o == this)
return 0;
if (o instanceof DelayedItem) {
DelayedItem<T> tmpDelayedItem = (DelayedItem<T>) o;
if (liveTime > tmpDelayedItem.liveTime) {
return 1;
} else if (liveTime == tmpDelayedItem.liveTime) {
return 0;
} else {
return -1;
}
}
long diff = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
return diff > 0 ? 1 : diff == 0 ? 0 : -1;
}
项目:JavaCommon
文件:Exam.java
@Override
public int compareTo(Delayed o) {
// TODO Auto-generated method stub
if (o == null || !(o instanceof Student))
return 1;
if (o == this)
return 0;
Student s = (Student) o;
if (this.workTime > s.workTime) {
return 1;
} else if (this.workTime == s.workTime) {
return 0;
} else {
return -1;
}
}
项目:JRediClients
文件:RedissonScheduledFuture.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
if (diff == 0) {
return 0;
}
if (diff < 0) {
return -1;
}
return 1;
}
项目:devtools-driver
文件:FakeScheduledExecutorService.java
@Override
public int compareTo(Delayed other) {
if (other == this) { // compare zero ONLY if same object
return 0;
}
FixedDelayedFuture<?> that = (FixedDelayedFuture<?>) other;
long diff = timeToRun - that.timeToRun;
if (diff < 0) {
return -1;
} else if (diff > 0) {
return 1;
} else if (sequenceId < that.sequenceId) {
return -1;
} else {
return 1;
}
}
项目:nh-micro
文件:MicroDelayItem.java
public int compareTo(Delayed other) {
if (other == this) // compare zero ONLY if same object
return 0;
if (other instanceof MicroDelayItem) {
MicroDelayItem x = (MicroDelayItem) other;
long diff = time - x.time;
if (diff < 0)
return -1;
else if (diff > 0)
return 1;
else if (sequenceNumber < x.sequenceNumber)
return -1;
else
return 1;
}
long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS));
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
项目:otter-G
文件:DeadNodeListener.java
public synchronized void processChanged(List<Long> nodes) {
Set<Long> deadNodes = new HashSet<Long>();
for (Long node : currentNodes) {
if (!nodes.contains(node)) {
deadNodes.add(node);
}
}
currentNodes = nodes;// 切换引用,需设置为volatile保证线程安全&可见性
// 处理下dead node
if (deadNodes.size() > 0) {
for (Long nid : deadNodes) {
Delayed delayed = new DeadNodeDelayed(nid, checkTime);
if (!queue.contains(delayed)) {// 不重复添加
queue.add(new DeadNodeDelayed(nid, checkTime));
}
}
}
}
项目:ios-device-control
文件:FakeScheduledExecutorService.java
@Override
public int compareTo(Delayed other) {
if (other == this) { // compare zero ONLY if same object
return 0;
}
FixedDelayedFuture<?> that = (FixedDelayedFuture<?>) other;
long diff = timeToRun - that.timeToRun;
if (diff < 0) {
return -1;
} else if (diff > 0) {
return 1;
} else if (sequenceId < that.sequenceId) {
return -1;
} else {
return 1;
}
}
项目:hadoop
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:openjdk-jdk10
文件:Stress.java
public static void main(String[] args) throws Throwable {
final DelayQueue<Delayed> q = new DelayQueue<>();
final long t0 = System.nanoTime();
for (long i = 0; i < 1000; i++) {
final long expiry = t0 + i*10L*1000L*1000L;
q.add(new Delayed() {
public long getDelay(TimeUnit unit) {
return unit.convert(expiry - System.nanoTime(),
NANOSECONDS);
}
public int compareTo(Delayed x) {
long d = getDelay(NANOSECONDS)
- x.getDelay(NANOSECONDS);
return d < 0 ? -1 : d > 0 ? 1 : 0; }});
}
for (int i = 0; i < 300; i++)
new Thread() { public void run() {
try {
while (!q.isEmpty())
q.poll(10L, TimeUnit.SECONDS);
} catch (Throwable t) { t.printStackTrace(); }
}}.start();
}
项目:openjdk9
文件:Stress.java
public static void main(String[] args) throws Throwable {
final DelayQueue<Delayed> q = new DelayQueue<Delayed>();
final long t0 = System.nanoTime();
for (long i = 0; i < 1000; i++) {
final long expiry = t0 + i*10L*1000L*1000L;
q.add(new Delayed() {
public long getDelay(TimeUnit unit) {
return unit.convert(expiry - System.nanoTime(),
NANOSECONDS);
}
public int compareTo(Delayed x) {
long d = getDelay(NANOSECONDS)
- x.getDelay(NANOSECONDS);
return d < 0 ? -1 : d > 0 ? 1 : 0; }});
}
for (int i = 0; i < 300; i++)
new Thread() { public void run() {
try {
while (!q.isEmpty())
q.poll(10L, TimeUnit.SECONDS);
} catch (Throwable t) { t.printStackTrace(); }
}}.start();
}
项目:aliyun-oss-hadoop-fs
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:big-c
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:nh-micro
文件:MicroDelayItem.java
public int compareTo(Delayed other) {
if (other == this) // compare zero ONLY if same object
return 0;
if (other instanceof MicroDelayItem) {
MicroDelayItem x = (MicroDelayItem) other;
long diff = time - x.time;
if (diff < 0)
return -1;
else if (diff > 0)
return 1;
else if (sequenceNumber < x.sequenceNumber)
return -1;
else
return 1;
}
long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS));
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
项目:j2se_for_android
文件:TimerQueue.java
public int compareTo(Delayed other) {
if (other == this) {
return 0;
}
if (other instanceof DelayedTimer) {
DelayedTimer x = (DelayedTimer) other;
long diff = time - x.time;
if (diff < 0) {
return -1;
} else if (diff > 0) {
return 1;
} else if (sequenceNumber < x.sequenceNumber) {
return -1;
} else {
return 1;
}
}
long d = (getDelay(TimeUnit.NANOSECONDS) - other
.getDelay(TimeUnit.NANOSECONDS));
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
项目:tracing-framework
文件:ThrottlingDelayQueue.java
@Override
public int compareTo(Delayed other) {
if (other instanceof ThrottlingDelayQueue.TenantThrottler) {
long onext = ((ThrottlingDelayQueue.TenantThrottler) other).next;
if (next < onext)
return -1;
else if (next == onext)
return 0;
else
return 1;
} else {
long odelay = other.getDelay(TimeUnit.NANOSECONDS);
long tdelay = this.getDelay(TimeUnit.NANOSECONDS);
if (tdelay < odelay)
return -1;
else if (tdelay == odelay)
return 0;
else
return 1;
}
}
项目:hadoop-2.6.0-cdh5.4.3
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:hadoop-2.6.0-cdh5.4.3
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:hadoop-EAR
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:LanternServer
文件:TaskExecutorService.java
@SuppressWarnings("rawtypes")
@Override
public int compareTo(Delayed other) {
// Since getDelay may return different values for each call,
// this check is required to correctly implement Comparable
if (other == this) {
return 0;
}
// If we are considering other sponge tasks, we can order by
// their internal tasks
if (other instanceof SpongeTaskFuture) {
ScheduledTask otherTask = ((SpongeTaskFuture) other).task;
return ComparisonChain.start()
.compare(this.task.nextExecutionTimestamp(), otherTask.nextExecutionTimestamp())
.compare(this.task.getUniqueId(), otherTask.getUniqueId())
.result();
}
return Long.compare(this.getDelay(TimeUnit.NANOSECONDS), other.getDelay(TimeUnit.NANOSECONDS));
}
项目:youscope
文件:MeasurementImpl.java
@Override
public int compareTo(Delayed otherRaw)
{
if(!(otherRaw instanceof ScheduledTask))
throw new ClassCastException("Only expecting elements of class ScheduledTask in scheduledTasksQueue.");
ScheduledTask other = (ScheduledTask)otherRaw;
if(scheduledRuntime < other.scheduledRuntime)
return -1;
else if(scheduledRuntime > other.scheduledRuntime)
return 1;
else if(scheduledTaskID < other.scheduledTaskID)
return -1;
else if(scheduledTaskID > other.scheduledTaskID)
return 1;
else
return 0;
}
项目:hadoop-plus
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:netty4.0.27Learn
文件:ScheduledFutureTask.java
@Override
public int compareTo(Delayed o) {
if (this == o) {
return 0;
}
ScheduledFutureTask<?> that = (ScheduledFutureTask<?>) o;
long d = deadlineNanos() - that.deadlineNanos();
if (d < 0) {
return -1;
} else if (d > 0) {
return 1;
} else if (id < that.id) {
return -1;
} else if (id == that.id) {
throw new Error();
} else {
return 1;
}
}
项目:gcmccsmock
文件:ScheduledJob.java
@Override
public int compareTo(Delayed o) {
if (this == o) {
return 0;
}
if (o == null) {
throw new IllegalArgumentException("null delayed element");
}
long delay = this.getScheduledTime();
long other = ((ScheduledJob)o).getScheduledTime();
if (delay == other) {
return 0;
} else if (delay > other) {
return 1;
} else {
return -1;
}
}
项目:hops
文件:GridmixJob.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
if (other instanceof GridmixJob) {
final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
if (otherNanos < submissionTimeNanos) {
return 1;
}
if (otherNanos > submissionTimeNanos) {
return -1;
}
return id() - ((GridmixJob)other).id();
}
final long diff =
getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
项目:GitHub
文件:TestScheduledFuture.java
@Override
public int compareTo(Delayed delayed) {
long me = getDelay(TimeUnit.MILLISECONDS);
long other = delayed.getDelay(TimeUnit.MILLISECONDS);
if (me < other) {
return -1;
} if (me > other) {
return 1;
} else {
return 0;
}
}
项目:incubator-netbeans
文件:RequestProcessor.java
@Override
public int compareTo(Delayed o) {
long other = o.getDelay(TimeUnit.MILLISECONDS);
long ours = getDelay(TimeUnit.MILLISECONDS);
//Might overflow on, say, ms compared to Long.MAX_VALUE, TimeUnit.DAYS
return (int) (ours - other);
}
项目:SensorThingsProcessor
文件:ProcessorBatchAggregate.java
@Override
public int compareTo(Delayed o) {
CalculationOrder other = (CalculationOrder) o;
return ComparisonChain.start()
.compare(targetMillis, other.targetMillis)
.compareTrueFirst(waiting.get(), other.waiting.get())
.compare(combo, other.combo)
.compare(interval.getStart(), other.interval.getStart())
.result();
}
项目:DBus
文件:DelayItem.java
@Override
public int compareTo(Delayed o) {
int ret = 0;
DelayItem target = (DelayItem) o;
if (this.trigger - target.trigger > 0) {
ret = 1;
} else if (this.trigger - target.trigger < 0) {
ret = -1;
}
return ret;
}
项目:habpanelviewer
文件:Average.java
@Override
public int compareTo(@NonNull Delayed delayed) {
if (delayed == this) {
return 0;
}
return Long.compare(getDelay(TimeUnit.MILLISECONDS), delayed.getDelay(TimeUnit.MILLISECONDS));
}
项目:lams
文件:ReschedulingRunnable.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
return (diff == 0 ? 0 : ((diff < 0)? -1 : 1));
}
项目:lams
文件:TimerManagerTaskScheduler.java
@Override
public int compareTo(Delayed other) {
if (this == other) {
return 0;
}
long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
return (diff == 0 ? 0 : ((diff < 0)? -1 : 1));
}
项目:otter-G
文件:DeadNodeListener.java
public int compareTo(Delayed other) {
if (other == this) { // compare zero ONLY if same object
return 0;
} else if (other instanceof DeadNodeDelayed) {
DeadNodeDelayed x = (DeadNodeDelayed) other;
long diff = now + timeout - (x.now + x.timeout);
return (diff == 0) ? 0 : ((diff < 0) ? 1 : -1); // 时间越小的,越应该排在前面
} else {
long d = (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
return (d == 0) ? 0 : ((d < 0) ? 1 : -1);
}
}
项目:otter-G
文件:AlarmRecoveryDelayed.java
public int compareTo(Delayed other) {
if (other == this) { // compare zero ONLY if same object
return 0;
} else if (other instanceof AlarmRecoveryDelayed) {
AlarmRecoveryDelayed x = (AlarmRecoveryDelayed) other;
long diff = now + timeout - (x.now + x.timeout);
return (diff == 0) ? 0 : ((diff < 0) ? 1 : -1); // 时间越小的,越应该排在前面
} else {
long d = (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
return (d == 0) ? 0 : ((d < 0) ? 1 : -1);
}
}
项目:ProxyPool
文件:Proxy.java
@Override
public int compareTo(Delayed o) {
Proxy element = (Proxy)o;
if (successfulAverageTime == 0.0d ||element.successfulAverageTime == 0.0d){
return 0;
}
return successfulAverageTime > element.successfulAverageTime ? 1:(successfulAverageTime < element.successfulAverageTime ? -1 : 0);
}
项目:Java-9-Concurrency-Cookbook-Second-Edition
文件:Event.java
/**
* Method to compare two events
*/
@Override
public int compareTo(Delayed o) {
long result = this.getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
}
return 0;
}
项目:hadoop
文件:ContainerSimulator.java
@Override
public int compareTo(Delayed o) {
if (!(o instanceof ContainerSimulator)) {
throw new IllegalArgumentException(
"Parameter must be a ContainerSimulator instance");
}
ContainerSimulator other = (ContainerSimulator) o;
return (int) Math.signum(endTime - other.endTime);
}
项目:hadoop
文件:TaskRunner.java
@Override
public int compareTo(Delayed o) {
if (!(o instanceof Task)) {
throw new IllegalArgumentException("Parameter must be a Task instance");
}
Task other = (Task) o;
return (int) Math.signum(nextRun - other.nextRun);
}
项目:openjdk-jdk10
文件:ScheduledTickleService.java
public int compareTo(Delayed other) {
if (this == other)
return 0;
else if (other instanceof CustomRunnableScheduledFuture)
return task.compareTo(((CustomRunnableScheduledFuture)other).task());
else
return task.compareTo(other);
}
项目:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming
文件:Event.java
/**
* Method to compare two events
*/
@Override
public int compareTo(Delayed o) {
long result = this.getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
}
return 0;
}
项目:think-in-java
文件:DelayQueueDemo.java
@Override
public int compareTo(Delayed arg)
{
DelayedTask that = (DelayedTask) arg;
if (trigger < that.trigger)
{
return -1;
}
if (trigger > that.trigger)
{
return 1;
}
return 0;
}