Example usage for java.lang System nanoTime

List of usage examples for java.lang System nanoTime

Introduction

In this page you can find the example usage for java.lang System nanoTime.

Prototype

@HotSpotIntrinsicCandidate
public static native long nanoTime();

Source Link

Document

Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.

Usage

From source file:org.smigo.config.RequestLogFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse resp = (HttpServletResponse) response;
    HttpServletRequest req = (HttpServletRequest) request;
    resp.addHeader("SmigoUser", req.getRemoteUser());
    log.info("Incoming request:" + req.getMethod() + req.getRequestURL().toString());
    request.setAttribute(REQUEST_TIMER, System.nanoTime());
    chain.doFilter(request, response);/*from  ww  w.  j a v  a 2s .  co m*/
    logHandler.log(req, resp);
}

From source file:net.duckling.ddl.util.ImageUtils.java

/**
 * ??// www  .  j a va 2s  . c  o m
 * @param  in ?
 * @return ?
 * */
public static String saveAsFile(InputStream in) {
    String fileName = PATH + TEMP + System.nanoTime();
    try {
        File directory = new File(PATH);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        File file = new File(fileName);
        FileOutputStream fos = new FileOutputStream(file);
        IOUtils.copy(in, fos);
        in.close();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException("save tmp file error:" + fileName, e);
    }
    return fileName;
}

From source file:net.rwx.maven.asciidoc.utils.FileUtils.java

private static String getTemporayAsciidoc() throws IOException {

    if (temporaryDirectory == null) {
        StringBuilder builder = new StringBuilder();

        builder.append(getTempDirectoryPath());
        builder.append(File.separator);
        builder.append("asciidoc-maven-plugin");
        builder.append(Long.toString(System.nanoTime()));
        temporaryDirectory = new File(builder.toString());
        forceMkdir(temporaryDirectory);//from   www  .  j a v  a2  s .co  m
        forceDeleteOnExit(temporaryDirectory);
    }
    // File f = File.createTempFile("tempAsciidoc", Long.toString(System.nanoTime()));
    // forceMkdir( f );
    // forceDeleteOnExit( f );
    return temporaryDirectory.getAbsolutePath();

}

From source file:com.l2jfree.network.mmocore.AbstractSelectorThread.java

@Override
public final void run() {
    // main loop//  w ww .  j a  va 2s. c o m
    for (;;) {
        final long begin = System.nanoTime();

        try {
            cleanup();

            // check for shutdown
            if (isShuttingDown()) {
                close();
                return;
            }

            try {
                if (getSelector().selectNow() > 0) {
                    Set<SelectionKey> keys = getSelector().selectedKeys();

                    for (SelectionKey key : keys) {
                        handle(key);
                    }

                    keys.clear();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            cleanup();
        } finally {
            RunnableStatsManager.handleStats(getClass(), "selectNow()", System.nanoTime() - begin);
        }

        try {
            Thread.sleep(getSleepTime());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.redhat.developers.containers.MyController.java

@CrossOrigin
@RequestMapping(method = RequestMethod.GET, value = "/memory", produces = "text/plain")
public String memory() {
    System.out.println("Starting to allocate memory...");
    Runtime rt = Runtime.getRuntime();
    StringBuilder sb = new StringBuilder();
    long maxMemory = rt.maxMemory();
    long usedMemory = 0;
    while (((float) usedMemory / maxMemory) < 0.80) {
        sb.append(System.nanoTime() + sb.toString());
        usedMemory = rt.totalMemory();//from ww  w.j  a  va2 s  .co  m
    }
    String msg = "Allocated more than 80% (" + humanReadableByteCount(usedMemory, false)
            + ") of the max allowed JVM memory size (" + humanReadableByteCount(maxMemory, false) + ")";
    System.out.println(msg);
    return msg;
}

From source file:com.taobao.ad.easyschedule.commons.utils.JobUtil.java

/**
 * ??URL//from   ww  w . j av a2  s . co  m
 * 
 * @param jobId
 * @param jobDetail
 * @param baseUrl
 * @return
 * @throws UnsupportedEncodingException
 */
public static String getJobTargetUrl(Long jobId, JobDetail jobDetail, String[] baseUrl)
        throws UnsupportedEncodingException {
    return getJobTargetUrl(jobId, jobDetail,
            baseUrl[Math.abs((System.nanoTime() + "").hashCode()) % baseUrl.length]);
}

From source file:com.codefollower.lealone.omid.tso.TestLongCache.java

@Test
public void testEntriesAge() {

    Cache cache = new LongCache(entries, 16);
    Random random = new Random();

    long seed = random.nextLong();

    LOG.info("Random seed: " + seed);
    random.setSeed(seed);/*from w  w  w.  ja va2 s.  co m*/
    int removals = 0;
    long totalAge = 0;
    double tempStdDev = 0;
    double tempAvg = 0;

    int i = 0;
    int largestDeletedTimestamp = 0;
    for (; i < entries * 10; ++i) {
        long removed = cache.set(random.nextLong(), i);
        if (removed > largestDeletedTimestamp) {
            largestDeletedTimestamp = (int) removed;
        }
    }

    long time = System.nanoTime();
    for (; i < entries * 100; ++i) {
        long removed = cache.set(random.nextLong(), i);
        if (removed > largestDeletedTimestamp) {
            largestDeletedTimestamp = (int) removed;
        }
        int gap = i - ((int) largestDeletedTimestamp);
        removals++;
        totalAge += gap;
        double oldAvg = tempAvg;
        tempAvg += (gap - tempAvg) / removals;
        tempStdDev += (gap - oldAvg) * (gap - tempAvg);
        hist.add(gap);
    }
    long elapsed = System.nanoTime() - time;
    LOG.info("Elapsed (ms): " + (elapsed / (double) 1000));

    double avgGap = totalAge / (double) removals;
    LOG.info("Avg gap: " + (tempAvg));
    LOG.info("Std dev gap: " + Math.sqrt((tempStdDev / entries)));
    assertThat(avgGap, is(greaterThan(entries * .6)));
}

From source file:org.apache.sling.distribution.it.DistributionPackageExporterImporterTemporaryFoldersTest.java

@Test
public void testAddExportImportTemp() throws Exception {

    List<String> jcrPackages = null;

    String nodePath = createRandomNode(publishClient, "/content/export_" + System.nanoTime());
    assertExists(publishClient, nodePath);

    distribute(publish, "temp", DistributionRequestType.ADD, nodePath);

    jcrPackages = getChildrenForFolder(publish, "/var/sling/distribution/packages/tempvlt/data");
    assertEquals(1, jcrPackages.size());

    publishClient.delete(nodePath);//from  w w  w.  ja  v  a2  s.  co  m
    assertNotExists(publishClient, nodePath);

    String content = doExport(publish, "temp", DistributionRequestType.PULL);

    jcrPackages = getChildrenForFolder(publish, "/var/sling/distribution/packages/tempvlt/data");
    assertEquals(0, jcrPackages.size());

    doImport(publish, "temp", content.getBytes(HTTP.DEFAULT_CONTENT_CHARSET));
    assertExists(publishClient, nodePath);

}

From source file:org.cloudbyexample.dc.service.si.application.ApplicationFlowTest.java

@Test
public void testApplicationFlow() {
    long start = System.nanoTime();

    Application application = createApplication();

    applicationFlow.process(application);

    long end = System.nanoTime();

    // waiting for SI threads to end
    try {//w  w w  .j a v  a2  s.c o  m
        Thread.sleep(6000);
    } catch (InterruptedException e) {
    }

    logger.info("Application flow test took {}ns", (end - start) / count);
}

From source file:com.centeractive.ws.builder.DefinitionSaveTest.java

public static File getGeneratedFolder(int serviceId) throws WSDLException, IOException {
    URL wsdlUrl = ServiceComplianceTest.getDefinitionUrl(serviceId);
    SoapBuilder builder = new SoapBuilder(wsdlUrl);
    File tempFolder = File.createTempFile("maven-temp", Long.toString(System.nanoTime()));
    if (!tempFolder.delete()) {
        throw new RuntimeException("cannot delete tmp file");
    }/*from  ww  w.  j a  va2s  .com*/
    if (!tempFolder.mkdir()) {
        throw new RuntimeException("cannot create tmp folder");
    }
    String fileName = FilenameUtils.getBaseName(wsdlUrl.toString());
    builder.saveWsdl(fileName, tempFolder);
    tempFolder.deleteOnExit();
    return tempFolder;
}