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


Java Delayed类代码示例

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


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

示例1: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:20,代码来源:Cache.java

示例2: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:17,代码来源:Exam.java

示例3: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:RedissonScheduledFuture.java

示例4: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
  }
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:18,代码来源:FakeScheduledExecutorService.java

示例5: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
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);
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:19,代码来源:MicroDelayItem.java

示例6: processChanged

import java.util.concurrent.Delayed; //导入依赖的package包/类
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));
            }
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:20,代码来源:DeadNodeListener.java

示例7: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:GridmixJob.java

示例8: main

import java.util.concurrent.Delayed; //导入依赖的package包/类
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();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Stress.java

示例9: main

import java.util.concurrent.Delayed; //导入依赖的package包/类
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();
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:Stress.java

示例10: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
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);
}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:22,代码来源:TimerQueue.java

示例11: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:22,代码来源:ThrottlingDelayQueue.java

示例12: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:TaskExecutorService.java

示例13: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
}
 
开发者ID:langmo,项目名称:youscope,代码行数:18,代码来源:MeasurementImpl.java

示例14: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:21,代码来源:ScheduledFutureTask.java

示例15: compareTo

import java.util.concurrent.Delayed; //导入依赖的package包/类
@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;
  }
}
 
开发者ID:lidennis88,项目名称:gcmccsmock,代码行数:21,代码来源:ScheduledJob.java


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