net.openhft.chronicle.core.Jvm.pause()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中net.openhft.chronicle.core.Jvm.pause()方法的一些代码示例,展示了Jvm.pause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jvm.pause()方法的具体详情如下:
包路径:net.openhft.chronicle.core.Jvm
类名称:Jvm
方法名:pause

Jvm.pause介绍

[英]Silently pause for milli seconds.
[中]安静地暂停几毫秒。

代码示例

代码示例来源:origin: OpenHFT/Chronicle-Queue

public static <T, R> R doWithExclusiveLock(File file, Function<T, ? extends R> code, Supplier<T> target) {
  final long timeoutAt = System.currentTimeMillis() + timeoutMS;
  boolean warnedOnFailure = false;
  try (final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE)) {
    while (System.currentTimeMillis() < timeoutAt) {
      try {
        FileLock fileLock = channel.tryLock();
        if (fileLock != null) {
          return code.apply(target.get());
        }
      } catch (IOException | OverlappingFileLockException e) {
        // failed to acquire the lock, wait until other operation completes
        if (!warnedOnFailure) {
          LOG.debug("Failed to acquire a lock on the table store file. Retrying");
          warnedOnFailure = true;
        }
      }
      Jvm.pause(50L);
    }
  } catch (IOException e) {
    throw new IllegalStateException("Couldn't perform operation with file lock", e);
  }
  throw new IllegalStateException("Unable to claim exclusive lock on file " + file);
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@After
public void checkMappedFiles() {
  System.gc();
  Jvm.pause(50);
  MappedFile.checkMappedFiles();
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@After
  public void checkMappedFiles() {
    System.gc();
    Jvm.pause(50);

    MappedFile.checkMappedFiles();
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Override
  public void writeMarshallable(@NotNull WireOut wire) {
    ValueOut valueOut = wire.getValueOut();
    for (int i = 0; i < NUMBER_OF_LONGS; i++)
      valueOut.int64(i);
    Jvm.pause(writePauseMs);
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

boolean fileFound = false;
for (int i = 0; i < 20; i++) {
  Jvm.pause(10);
  if ((fileFound = (
      currentCycle <= directoryListing.getMaxCreatedCycle() &&

代码示例来源:origin: OpenHFT/Chronicle-Queue

private void moveToSpecifiedPosition(final ChronicleQueue ic, final ExcerptTailer tailer, final boolean isFirstIteration) {
  if (isSet(startIndex) && isFirstIteration) {
    if (startIndex < ic.firstIndex()) {
      throw new IllegalArgumentException(String.format("startIndex %d is less than first index %d",
          startIndex, ic.firstIndex()));
    }
    messageSink.accept("Waiting for startIndex " + startIndex);
    for (; ; ) {
      if (tailer.moveToIndex(startIndex))
        break;
      Jvm.pause(100);
    }
  }
  if (isSet(maxHistoryRecords) && isFirstIteration) {
    tailer.toEnd();
    tailer.moveToIndex(Math.max(ic.firstIndex(), tailer.index() - maxHistoryRecords));
  } else if (tailInputSource && isFirstIteration) {
    tailer.toEnd();
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

while (!thread.isInterrupted()) {
    appender.pretouch();
    Jvm.pause(10);
Jvm.pause(250); // give the reader time to start
long next = System.nanoTime();
long end = (long) (next + runtime * 1e9);
  Jvm.pause(50);
System.out.println("read histogram: " + readTime.toMicrosFormat());
IOTools.deleteDirWithFiles(path, 2);
Jvm.pause(1000);

代码示例来源:origin: OpenHFT/Chronicle-Queue

long delay = 10000 - time0;
if (delay > 0)
  Jvm.pause(delay);

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Override
public Throwable call() {
  try (final ChronicleQueue queue = queue()) {
    final ExcerptAppender appender = queue.acquireAppender();
    Jvm.pause(random.nextInt(DELAY_WRITER_RANDOM_MS));
    final long startTime = System.nanoTime();
    int loopIteration = 0;
    while (true) {
      final int value = write(appender);
      while (System.nanoTime() < (startTime + (loopIteration * SLEEP_PER_WRITE_NANOS))) {
        // spin
      }
      loopIteration++;
      if (value >= expectedNumberOfMessages) {
        return null;
      }
    }
  } catch (Throwable e) {
    exception = e;
    return e;
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

public StartAndMonitor(ChronicleQueue queue, String name, int writePauseMs, int sleepBetweenMillis) {
      final SlowToSerialiseAndDeserialise object = new SlowToSerialiseAndDeserialise(writePauseMs);
      Thread thread = new Thread(() -> {
        try {
          while (running.get()) {
            long loopStart = System.nanoTime();
            final ExcerptAppender appender = queue.acquireAppender();
//                        System.out.println("about to open");
            try (final DocumentContext ctx = appender.writingDocument()) {
//                            System.out.println("about to write");
              ctx.wire().getValueOut().marshallable(object);
//                            System.out.println("about to close");
            }
//                        System.out.println("closed");
            long timeTaken = System.nanoTime() - loopStart;
            histo.sampleNanos(timeTaken);
            Jvm.pause(sleepBetweenMillis);
          }
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }, name);
      thread.start();
    }
  }

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Override
  public Throwable call() throws Exception {
    ChronicleQueue queue0 = null;
    try (ChronicleQueue queue = queueBuilder(path).build()) {
      queue0 = queue;
      ExcerptAppender appender = queue.acquireAppender();
      System.out.println("Starting pretoucher");
      while (!Thread.currentThread().isInterrupted() && !queue.isClosed()) {
        Jvm.pause(50);
        appender.pretouch();
      }
    } catch (Throwable e) {
      if (queue0 != null && queue0.isClosed())
        return null;
      exception = e;
      return e;
    }
    return null;
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

long millis = System.currentTimeMillis() % 1000;
if (millis > 1 && millis < 999) {
  Jvm.pause(999 - millis);

代码示例来源:origin: OpenHFT/Chronicle-Queue

} else {
        Jvm.pause(10);
Jvm.pause(500); //TODO: latch
Jvm.pause(500);

代码示例来源:origin: OpenHFT/Chronicle-Queue

System.out.println("documentContext.isPresent=" + present
          + (present ? ",index=" + Long.toHexString(index) : ", no index"));
      Jvm.pause(50);
((SingleChronicleQueueExcerpts.StoreAppender) wqueue.acquireAppender())
    .writeEndOfCycleIfRequired();
Jvm.pause(200);
wqueue.acquireAppender().writeText("hello world");
f.get();

代码示例来源:origin: OpenHFT/Chronicle-Queue

int lastTailerCycle = -1;
int lastQueueCycle = -1;
Jvm.pause(random.nextInt(DELAY_READER_RANDOM_MS));
while (lastRead != expectedNumberOfMessages - 1) {
  try (DocumentContext dc = tailer.readingDocument()) {

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void test() {
  File dir = getTmpDir();
  try (final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(dir, wireType)
      .testBlockSize()
      .build()) {
    final ExcerptTailer tailer = queue.createTailer();
    assertFalse(tailer.readDocument(r -> r.read(TestKey.test).int32()));
    final ExcerptAppender appender = queue.acquireAppender();
    appender.writeDocument(w -> w.write(TestKey.test).int32(1));
    Jvm.pause(100);
    assertTrue(tailer.readDocument(r -> r.read(TestKey.test).int32()));
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

return;
Jvm.pause(1);

代码示例来源:origin: OpenHFT/Chronicle-Threads

void doPauseMS(long delayMS) {
  long start = System.nanoTime();
  pausing.set(true);
  Jvm.pause(delayMS);
  pausing.set(false);
  long time = System.nanoTime() - start;
  timePaused += time;
  countPaused++;
}

代码示例来源:origin: net.openhft/chronicle-engine

@Nullable
private Bytes getFileContentsFromDisk(@NotNull Path path, Bytes using) {
  for (int i = 1; i <= 5; i++) {
    try {
      return getFileContentsFromDisk0(path, using);
    } catch (IOException e) {
      pause(i * i * 2);
    }
  }
  return null;
}

代码示例来源:origin: net.openhft/chronicle-engine

@Override
public void close() {
  root.notifyClosing();
  Jvm.pause(50);
  // ensure that the event loop get shutdown first
  @Nullable EventLoop view = root().findView(EventLoop.class);
  Closeable.closeQuietly(view);
  root.close();
}

相关文章