本文整理汇总了Java中net.openhft.chronicle.core.Jvm.pause方法的典型用法代码示例。如果您正苦于以下问题:Java Jvm.pause方法的具体用法?Java Jvm.pause怎么用?Java Jvm.pause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.openhft.chronicle.core.Jvm
的用法示例。
在下文中一共展示了Jvm.pause方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delay
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
/**
* Delays, via Thread.sleep, for the given millisecond delay, but
* if the sleep is shorter than specified, may re-sleep or yield
* until time elapses.
*/
static void delay(long millis) throws InterruptedException {
long startTime = System.nanoTime();
long ns = millis * 1000 * 1000;
for (; ; ) {
if (millis > 0L)
Jvm.pause(millis);
else // too short to sleep
Thread.yield();
long d = ns - (System.nanoTime() - startTime);
if (d > 0L)
millis = d / (1000 * 1000);
else
break;
}
}
示例2: check
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
public <R> R check(Call instance) {
R r1 = null;
R r2 = null;
for (int i = 0; i < 50; i++) {
r1 = (R) instance.method(map1);
r2 = (R) instance.method(map2);
if (r1 != null && r1.equals(r2))
return r1;
if (i > 30) {
Jvm.pause(i);
} else {
Thread.yield();
}
}
Assert.assertEquals(map1, map2);
System.out.print(map1);
System.out.print(map2);
if (r1 != null)
Assert.assertEquals(r1.toString(), r2.toString());
return (R) r1;
}
示例3: waitTillEqual
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
public static void waitTillEqual(Map map1, Map map2, int timeOutMs) {
int numberOfTimesTheSame = 0;
long startTime = System.currentTimeMillis();
for (int t = 0; t < timeOutMs + 100; t++) {
// not map1.equals(map2), the reason is described above
if (map1.equals(map2)) {
numberOfTimesTheSame++;
Jvm.pause(1);
if (numberOfTimesTheSame == 10) {
System.out.println("same");
break;
}
}
Jvm.pause(1);
if (System.currentTimeMillis() - startTime > timeOutMs)
break;
}
}
示例4: main
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
public static void main(String[] args) {
String input = args.length > 0 ? args[0] : OS.TMP + "/input";
String output = args.length > 1 ? args[1] : OS.TMP + "/output";
AtomicLong lastUpdate = new AtomicLong(System.currentTimeMillis() + 1000);
Thread thread = new Thread(() -> {
ChronicleQueue outputQ = SingleChronicleQueueBuilder.binary(output).build();
MethodReader reader = outputQ.createTailer().methodReader((HelloReplier) err::println);
while (!Thread.interrupted()) {
if (reader.readOne()) {
lastUpdate.set(System.currentTimeMillis());
} else {
Jvm.pause(10);
}
}
});
thread.setDaemon(true);
thread.start();
ChronicleQueue inputQ = SingleChronicleQueueBuilder.binary(input).build();
HelloWorld helloWorld = inputQ.createAppender().methodWriter(HelloWorld.class);
Scanner scanner = new Scanner(System.in);
while (true) {
while (System.currentTimeMillis() < lastUpdate.get() + 30)
Thread.yield();
out.print("Chat ");
out.flush();
if (!scanner.hasNextLine())
break;
String line = scanner.nextLine();
helloWorld.hello(line);
lastUpdate.set(System.currentTimeMillis());
}
out.print("Bye");
}
示例5: main
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
public static void main(String[] args) {
String path = "queue";
SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).build();
ExcerptTailer tailer = queue.createTailer();
while (true) {
String text = tailer.readText();
if (text == null)
Jvm.pause(10);
else
System.out.println(text);
}
}
示例6: run
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
@Override
public void run() {
while (running && !Thread.currentThread().isInterrupted()) {
Jvm.pause(1);
long delay = System.nanoTime() - sample;
if (delay > 1000 * 1000) {
System.out.println("\n" + (System.currentTimeMillis() - START_TIME) + " : Delay of " + delay / 100000 / 10.0 + " ms.");
int count = 0;
for (StackTraceElement ste : thread.getStackTrace()) {
System.out.println("\tat " + ste);
if (count++ > 6) break;
}
}
}
}
示例7: waitTillEqual
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
/**
* * waits until map1 and map2 show the same value
*
* @param timeOutMs timeout in milliseconds
*/
private void waitTillEqual(final int timeOutMs) {
int t = 0;
for (; t < timeOutMs; t++) {
if (map1.equals(map2))
break;
Jvm.pause(1);
}
}
示例8: run
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
final ExcerptTailer tailer = queue.createTailer();
final ByteBufMarshallable smm = new ByteBufMarshallable(compression);
startLatch.countDown();
while(keepRunning.get()) {
try {
long processed = 0L;
long reads = 0L;
int listenerProcessed = 0;
final long startTime = System.currentTimeMillis();
while(tailer.readBytes(smm)) {
chronicleReads.inc();
reads++;
final ByteBuf sm = smm.getAndNullByteBuf();
log.debug("MessageQueue Read Buffer, size: {} bytes", sm.readableBytes());
if(sm!=null) {
listenerProcessed += listener.onMetric(sm);
// sm.release();
processed++;
if(processed==stopCheckCount) {
processed = 0;
if(!keepRunning.get()) break;
}
}
}
if(reads==0) {
Jvm.pause(idlePauseTime);
} else {
final long elapsedTime = System.currentTimeMillis() - startTime;
log.info("Processed [{}] in [{}] ms.", listenerProcessed, elapsedTime);
}
reads = 0;
} catch (Exception ex) {
if(ex instanceof InterruptedException) {
if(keepRunning.get()) {
if(Thread.interrupted()) Thread.interrupted();
}
log.info("Reader Thread [{}] shutting down", Thread.currentThread());
} else {
log.warn("Unexpected exception in reader thread", ex);
}
}
}
}
示例9: main
import net.openhft.chronicle.core.Jvm; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
ProcessInstanceLimiter.limitTo(2);
Jvm.pause(60L * 1000L);
}