Example usage for java.lang System currentTimeMillis

List of usage examples for java.lang System currentTimeMillis

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native long currentTimeMillis();

Source Link

Document

Returns the current time in milliseconds.

Usage

From source file:com.talent.nio.utils.NetUtils.java

/**
 * @param args/*from ww w  . j a v  a 2 s  .co  m*/
 */
public static void main(String[] args) {
    try {
        long start1 = System.currentTimeMillis();
        boolean isConnect = isConnectable("127.0.0.1", 9898);

        long end1 = System.currentTimeMillis();
        System.out.println(isConnect + ":" + (end1 - start1) + "");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ch.rasc.wampspring.demo.client.CallClientSockJs.java

public static void main(String[] args) throws InterruptedException {

    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());
    WebSocketClient webSocketClient = new SockJsClient(transports);

    JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper());

    CountDownLatch latch = new CountDownLatch(10_000);
    TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch);

    Long[] start = new Long[1];
    ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler,
            "ws://localhost:8080/wampOverSockJS");
    future.addCallback(wss -> {/*from w ww. j a v  a2s  .c  o  m*/
        start[0] = System.currentTimeMillis();
        for (int i = 0; i < 10_000; i++) {

            CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i,
                    i + 1);
            try {
                wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory)));
            } catch (Exception e) {
                System.out.println("ERROR SENDING CALLMESSAGE" + e);
                latch.countDown();
            }
        }

    }, t -> {
        System.out.println("DO HANDSHAKE ERROR: " + t);
        System.exit(1);
    });

    if (!latch.await(3, TimeUnit.MINUTES)) {
        System.out.println("SOMETHING WENT WRONG");
    }

    System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds");
    System.out.println("SUCCESS: " + handler.getSuccess());
    System.out.println("ERROR  : " + handler.getError());
}

From source file:com.nubits.nubot.launch.NuPriceMonitor.java

public static void main(String[] args) {
    mainThread = Thread.currentThread();
    //Load settings
    Utils.loadProperties("settings.properties");

    String folderName = "NuPriceMonitor_" + System.currentTimeMillis() + "/";
    String logsFolder = Global.settings.getProperty("log_path") + folderName;
    //Create log dir
    FileSystem.mkdir(logsFolder);
    try {//from   w  w  w.j a v a  2s . c o m
        NuLogger.setup(false, logsFolder);
    } catch (IOException ex) {
        LOG.severe(ex.toString());
    }

    NuPriceMonitor app = new NuPriceMonitor();
    if (app.readParams(args)) {
        createShutDownHook();
        app.init();
        LOG.fine("Launching NuCheckPrice ");
        app.exec();
    } else {
        System.exit(0);
    }
}

From source file:com.sangupta.snowpack.SnowpackRecover.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println(/*  w w  w .  j a  v a  2 s  .c  o  m*/
                "Usage: java -classpath snowpack.jar com.sangupta.snowpack.SnowpackRecover <base-folder>");
        return;
    }

    File base = new File(args[0]);
    if (!base.exists()) {
        System.out.println("Base folder does not exists.");
        return;
    }

    if (!base.isDirectory()) {
        System.out.println("Base folder does not represent a valid directory on disk.");
        return;
    }

    long start = System.currentTimeMillis();
    recover(base);
    long end = System.currentTimeMillis();

    System.out.println("Recovery process complete in " + (end - start) + "ms.");
}

From source file:org.sandag.popsyn.PopulationSynthesizer.java

/**
 * Begins execution of PopSyn/*from   w w  w .j  ava  2 s  .c o  m*/
 * @param args  not used
 * @throws Exception    
 */
public static void main(String[] args) throws Exception {
    double startTime = System.currentTimeMillis();
    // load
    ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
    PopulationSynthesizer popSyn = appCtx.getBean(PopulationSynthesizer.class);
    // do work
    popSyn.synthesizePopulation();
    // time stamp
    LOGGER.info("Completed in: " + (float) (((System.currentTimeMillis() - startTime) / 1000.0) / 60.0)
            + " minutes.");
}

From source file:com.pnf.jebauto.AutoClient.java

public static void main(String[] argv) throws Exception {
    if (argv.length <= 0) {
        return;//from  w  w  w . j av  a 2  s . c o m
    }

    long t0 = System.currentTimeMillis();
    String location = argv[0];
    List<File> files = AutoUtil.retrieveFiles(location);
    test(files);
    logger.info("Done in %ds", (System.currentTimeMillis() - t0) / 1000);
}

From source file:com.khartec.waltz.jobs.sample.OrgUnitGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));

    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();

    List<OrganisationalUnitRecord> records = lines.stream().skip(1)
            .map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4)
            .map(cells -> {//from w w  w. j  av a2s  . co  m
                OrganisationalUnitRecord record = new OrganisationalUnitRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);
                record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();

    System.out.println("Done");

}

From source file:com.kynetx.ParseRuleset.java

public static void main(String[] args) throws Exception {
    File f = new File(args[0]);
    int notparsed = 0;
    int parsed = 0;

    File[] files = null;/*from www.j a v a2  s.  co  m*/
    if (f.isDirectory()) {
        files = f.listFiles();
    } else {
        files = new File[1];
        files[0] = new File(args[0]);
    }
    for (int i = 0; i < files.length; i++) {
        File thefile = files[i];
        long start = System.currentTimeMillis();
        boolean skipfile = false;
        for (int ii = 0; ii < ignore.length; ii++) {
            if (thefile.getCanonicalPath().indexOf(ignore[ii] + ".krl") > 0) {
                skipfile = true;
                break;
            }
        }
        if (thefile.length() == 0 || thefile.length() == 31 || thefile.length() == 162 || skipfile) {
            notparsed = notparsed + 1;
            //               System.out.println("Skipping: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //               System.out.println("Skipping " + thefile);
            continue;
        }
        parsed = parsed + 1;
        try {
            ANTLRFileStream input = new ANTLRFileStream(thefile.getCanonicalPath());
            com.kynetx.RuleSetLexer lexer = new com.kynetx.RuleSetLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            com.kynetx.RuleSetParser parser = new com.kynetx.RuleSetParser(tokens);
            parser.ruleset();
            JSONObject js = new JSONObject(parser.rule_json);
            if (parser.parse_errors.size() > 0) {
                for (int ii = 0; ii < parser.parse_errors.size(); ii++) {
                    System.err
                            .println("ERROR FOUND " + parser.parse_errors.get(ii) + " - " + thefile.toString());
                }
            }
            //               System.out.println("Parsed: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            //System.out.println(unescapeUnicode(js.toString()));
            System.out.println(js.toString());
            //System.out.println("=============");
            //System.out.println(js.toString());
        } catch (Exception e) {
            //               System.out.println("Error: " + thefile + " in " + (System.currentTimeMillis() - start) + "ms." );
            System.out.println("Error " + thefile + " " + e.getMessage());
            e.printStackTrace();
        }
    }
    //         System.out.println("Not Parsed " + notparsed);
    //         System.out.println("Parsed " + parsed);

}

From source file:com.ciphertool.zodiacengine.CipherSolutionEngine.java

/**
 * @param args/*from   www  . j  a  v a2  s . c  om*/
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {
    // Spin up the Spring application context
    setUp();

    CipherDto cipherDto = null;
    Runnable cipherTask = null;
    Thread cipherWorker = null;
    long threadIterations = 0;
    Cipher cipher = cipherDao.findByCipherName(cipherName);

    long start = System.currentTimeMillis();

    List<Thread> threads = new ArrayList<Thread>();
    List<CipherDto> cipherDtos = new ArrayList<CipherDto>();

    if (maxThreads > numIterations) {
        log.warn("The number of threads is greater than the number of tasks.  Reducing thread count to "
                + numIterations + ".");

        maxThreads = (int) numIterations;
    }

    log.info("Beginning solution generation.  Generating " + numIterations + " solutions using " + maxThreads
            + " threads.");

    for (int i = 1; i <= maxThreads; i++) {
        threadIterations = (numIterations / maxThreads);
        if (i == 1) {
            /*
             * If the number of iterations doesn't divide evenly among the
             * threads, add the remainder to the first thread
             */
            threadIterations += (numIterations % maxThreads);
        }

        cipherDto = new CipherDto(String.valueOf(i), cipher);
        cipherDtos.add(cipherDto);

        cipherTask = new CipherSolutionRunnable(threadIterations, solutionGenerator, solutionEvaluator,
                cipherDto);

        cipherWorker = new Thread(cipherTask, String.valueOf(i));

        cipherWorker.start();
        threads.add(cipherWorker);
    }

    /*
     * Keep checking threads until no more are left running
     */
    int running = 0;
    do {
        running = 0;
        for (Thread thread : threads) {
            if (thread.isAlive()) {
                running++;
            }
        }

        /*
         * There's no need to loop through this as fast as possible. Sleep
         * for a short period so that there isn't so much overhead from
         * monitoring the threads' state.
         */
        Thread.sleep(monitorSleepMillis);
    } while (running > 0);

    long totalSolutions = 0;
    long totalMatchSum = 0;
    long uniqueMatchSum = 0;
    long adjacentMatchSum = 0;

    BigInteger cipherId = cipher.getId();
    int rows = cipher.getRows();
    int columns = cipher.getColumns();
    SolutionChromosome solutionMostMatches = new SolutionChromosome(cipherId, 0, 0, 0, rows, columns);
    SolutionChromosome solutionMostUnique = new SolutionChromosome(cipherId, 0, 0, 0, rows, columns);
    SolutionChromosome solutionMostAdjacent = new SolutionChromosome(cipherId, 0, 0, 0, rows, columns);

    /*
     * Sum up all data from all CipherDtos passed to the threads
     */
    for (CipherDto nextCipherDto : cipherDtos) {
        log.debug("Best solution from thread " + nextCipherDto.getThreadName() + ": "
                + nextCipherDto.getSolutionMostMatches());
        log.debug("Most unique solution from thread " + nextCipherDto.getThreadName() + ": "
                + nextCipherDto.getSolutionMostUnique());
        log.debug("Solution with most adjacent matches from thread " + nextCipherDto.getThreadName() + ": "
                + nextCipherDto.getSolutionMostAdjacent());

        totalSolutions += nextCipherDto.getNumSolutions();
        totalMatchSum += nextCipherDto.getTotalMatchSum();
        uniqueMatchSum += nextCipherDto.getUniqueMatchSum();
        adjacentMatchSum += nextCipherDto.getAdjacentMatchSum();

        /*
         * Find the Solution with the highest number of total matches
         */
        if (nextCipherDto.getSolutionMostMatches().getTotalMatches() > solutionMostMatches.getTotalMatches()) {
            solutionMostMatches = nextCipherDto.getSolutionMostMatches();
        }

        /*
         * Find the Solution with the highest number of unique matches in
         * plaintext
         */
        if (nextCipherDto.getSolutionMostUnique().getUniqueMatches() > solutionMostUnique.getUniqueMatches()) {
            solutionMostUnique = nextCipherDto.getSolutionMostUnique();
        }

        /*
         * Find the Solution with the highest number of adjacent matches in
         * plaintext
         */
        if (nextCipherDto.getSolutionMostAdjacent().getAdjacentMatchCount() > solutionMostAdjacent
                .getAdjacentMatchCount()) {
            solutionMostAdjacent = nextCipherDto.getSolutionMostAdjacent();
        }
    }

    /*
     * Print out summary information
     */
    log.info("Took " + (System.currentTimeMillis() - start) + "ms to generate and validate " + totalSolutions
            + " solutions.");
    log.info("Most total matches achieved: " + solutionMostMatches.getTotalMatches());
    log.info("Average total matches: " + (totalMatchSum / totalSolutions));
    log.info("Best solution found: " + solutionMostMatches);
    log.info("Most unique matches achieved: " + solutionMostUnique.getUniqueMatches());
    log.info("Average unique matches: " + (uniqueMatchSum / totalSolutions));
    log.info("Solution with most unique matches found: " + solutionMostUnique);
    log.info("Most adjacent matches achieved: " + solutionMostAdjacent.getAdjacentMatchCount());
    log.info("Average adjacent matches: " + (adjacentMatchSum / totalSolutions));
    log.info("Solution with most adjacent matches found: " + solutionMostAdjacent);
}

From source file:TrainLogistic.java

public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();
    mainToOutput(args, new PrintWriter(System.out, true));
    System.out.printf("time:%.2f s\n", (double) (System.currentTimeMillis() - start) / 1000.0);
}