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.devoteam.srit.xmlloader.http.test.HttpLoaderClient.java

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Please specify hostname and port number");
        System.exit(1);//from   www .j av a  2 s  .c o  m
    }
    http = new HttpLoaderServer(args[0], Integer.parseInt(args[1]));
    http.testConnection();
    responseThread = new HttpLoaderClient(); // thread de gestion des reponses cot client
    responseThread.setDaemon(false);
    responseThread.start(); // lancement du processus de gestion des msg
    beginThreadRequest = System.currentTimeMillis(); // top chono des requetes
    for (int i = 0; i < 5000000; i++)
        testhttp.createRequest(i); // creation et envoie des messages au serveur
    endThreadRequest = System.currentTimeMillis();
    timeThreadRequest = endThreadRequest - beginThreadRequest; // calcul de la duree de l'envoie des msg'
}

From source file:com.damon.rocketmq.example.operation.Consumer.java

public static void main(String[] args) throws InterruptedException, MQClientException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String subscription = commandLine.getOptionValue('s');
        final String returnFailedHalf = commandLine.getOptionValue('f');

        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(group);
        consumer.setInstanceName(Long.toString(System.currentTimeMillis()));

        consumer.subscribe(topic, subscription);

        consumer.registerMessageListener(new MessageListenerConcurrently() {
            AtomicLong consumeTimes = new AtomicLong(0);

            @Override/* w ww . j a v  a  2s .  co  m*/
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                    ConsumeConcurrentlyContext context) {
                long currentTimes = this.consumeTimes.incrementAndGet();
                System.out.printf("%-8d %s%n", currentTimes, msgs);
                if (Boolean.parseBoolean(returnFailedHalf)) {
                    if ((currentTimes % 2) == 0) {
                        return ConsumeConcurrentlyStatus.RECONSUME_LATER;
                    }
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });

        consumer.start();

        System.out.printf("Consumer Started.%n");
    }
}

From source file:com.glaf.core.security.EncryptorFactory.java

public static void main(String[] args) throws Exception {
    Encryptor cryptor = EncryptorFactory.getEncryptor();
    System.out.println("EnCrypted text [" + cryptor.encrypt("111111") + "]");
    System.out.println("EnCrypted text [" + cryptor.decrypt("37306959717a76687534733d") + "]");

    for (int i = 0; i < 10; i++) {
        long start = System.currentTimeMillis();

        String encryptedText = cryptor.encrypt(UUID32.getUUID());
        System.out.println("EnCrypted text [" + encryptedText + "]");

        String decryptedText = cryptor.decrypt(encryptedText);
        System.out.println("DeCrypted text " + decryptedText);
        long ms = System.currentTimeMillis() - start;
        System.out.println(":" + (ms) + " .");
    }// w w  w. j  a v  a 2 s.  c  om
}

From source file:org.vuphone.vandyupon.test.ImagePostTester.java

public static void main(String[] args) {
    try {// ww  w.  jav a2  s  .  c o  m
        File image = new File("2008-05-8 ChrisMikeNinaGrad.jpg");
        byte[] bytes = new byte[(int) image.length()];
        FileInputStream fis = new FileInputStream(image);

        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        fis.close();

        HttpClient c = new DefaultHttpClient();
        HttpPost post = new HttpPost(
                "http://afrl-gift.dre.vanderbilt.edu:8080/vandyupon/events/?type=eventimagepost&eventid=2"
                        + "&time=" + System.currentTimeMillis() + "&resp=xml");

        post.addHeader("Content-Type", "image/jpeg");
        ByteArrayEntity bae = new ByteArrayEntity(bytes);
        post.setEntity(bae);

        try {
            HttpResponse resp = c.execute(post);
            resp.getEntity().writeTo(System.out);
        } catch (IOException e) {
            e.printStackTrace();
        }

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

From source file:eu.scape_project.tb.wc.archd.hadoop.HadoopArcReaderJob.java

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

    logger.info("HADOOP ARC reader test hadoop job.");
    long startTime = System.currentTimeMillis();

    int res = ToolRunner.run(new Configuration(), new HadoopArcReaderJob(), args);

    long elapsedTime = System.currentTimeMillis() - startTime;
    logger.info("Processing time (sec): " + elapsedTime / 1000F);

    System.exit(res);//  www .  jav  a  2  s  .  c  o  m
}

From source file:edu.msu.cme.rdp.readseq.ToFasta.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("m", "mask", true, "Mask sequence name indicating columns to drop");
    String maskSeqid = null;/*from  www .  ja v  a 2 s .  com*/

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("mask")) {
            maskSeqid = line.getOptionValue("mask");
        }

        args = line.getArgs();
        if (args.length == 0) {
            throw new Exception("");
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: to-fasta <input-file>", options);
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
        return;
    }

    SeqReader reader = null;

    FastaWriter out = new FastaWriter(System.out);
    Sequence seq;
    int totalSeqs = 0;
    long totalTime = System.currentTimeMillis();

    for (String fname : args) {
        if (fname.equals("-")) {
            reader = new SequenceReader(System.in);
        } else {
            File seqFile = new File(fname);

            if (maskSeqid == null) {
                reader = new SequenceReader(seqFile);
            } else {
                reader = new IndexedSeqReader(seqFile, maskSeqid);
            }
        }

        long startTime = System.currentTimeMillis();
        int thisFileTotalSeqs = 0;
        while ((seq = reader.readNextSequence()) != null) {
            out.writeSeq(seq.getSeqName().replace(" ", "_"), seq.getDesc(), seq.getSeqString());
            thisFileTotalSeqs++;
        }
        totalSeqs += thisFileTotalSeqs;
        System.err.println("Converted " + thisFileTotalSeqs + " (total sequences: " + totalSeqs
                + ") sequences from " + fname + " (" + reader.getFormat() + ") to fasta in "
                + (System.currentTimeMillis() - startTime) / 1000 + " s");
    }
    System.err.println("Converted " + totalSeqs + " to fasta in "
            + (System.currentTimeMillis() - totalTime) / 1000 + " s");

    out.close();
}

From source file:cn.ccrise.spimp.web.LoginController.java

public static void main(String[] args) {
    String day = new SimpleDateFormat("yyyy-MM-dd")
            .format(DateUtils.addDays(new Date(System.currentTimeMillis()), 365 * 20));
    String license = AES.encodeAes128(KEY, day);
    System.out.println(license);/*from w  w  w.  j a  v  a  2s  .c  o m*/
    System.out.println(AES.decodeAes128(KEY, license));
}

From source file:com.blogspot.devsk.l2j.geoconv.GeoGonv.java

public static void main(String[] args) {

    if (args == null || args.length == 0) {
        System.out.println("File name was not specified, [\\d]{1,2}_[\\d]{1,2}.txt will be used");
        args = new String[] { "[\\d]{1,2}_[\\d]{1,2}.txt" };
    }/*w  w  w.  j a  va2 s  . c  om*/

    File dir = new File(".");
    File[] files = dir.listFiles((FileFilter) new RegexFileFilter(args[0]));

    ArrayList<File> checked = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory() || file.isHidden() || !file.exists()) {
            System.out.println(file.getAbsoluteFile() + " was ignored.");
        } else {
            checked.add(file);
        }
    }

    if (OUT_DIR.exists() && OUT_DIR.isDirectory() && OUT_DIR.listFiles().length > 0) {
        try {
            System.out.println("Directory with generated files allready exists, making backup...");
            FileUtils.moveDirectory(OUT_DIR, new File("generated-backup-" + System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!OUT_DIR.exists()) {
        OUT_DIR.mkdir();
    }

    for (File file : checked) {
        GeoConvThreadFactory.startThread(new ParseTask(file));
    }
}

From source file:com.linkedin.pinotdruidbenchmark.PinotThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
        System.err.println(/*from   ww w .  j av a  2 s .c o  m*/
                "3 or 4 arguments required: QUERY_DIR, RESOURCE_URL, NUM_CLIENTS, TEST_TIME (seconds).");
        return;
    }

    File queryDir = new File(args[0]);
    String resourceUrl = args[1];
    final int numClients = Integer.parseInt(args[2]);
    final long endTime;
    if (args.length == 3) {
        endTime = Long.MAX_VALUE;
    } else {
        endTime = System.currentTimeMillis() + Integer.parseInt(args[3]) * MILLIS_PER_SECOND;
    }

    File[] queryFiles = queryDir.listFiles();
    assert queryFiles != null;
    Arrays.sort(queryFiles);

    final int numQueries = queryFiles.length;
    final HttpPost[] httpPosts = new HttpPost[numQueries];
    for (int i = 0; i < numQueries; i++) {
        HttpPost httpPost = new HttpPost(resourceUrl);
        String query = new BufferedReader(new FileReader(queryFiles[i])).readLine();
        httpPost.setEntity(new StringEntity("{\"pql\":\"" + query + "\"}"));
        httpPosts[i] = httpPost;
    }

    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);

    for (int i = 0; i < numClients; i++) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                    while (System.currentTimeMillis() < endTime) {
                        long startTime = System.currentTimeMillis();
                        CloseableHttpResponse httpResponse = httpClient
                                .execute(httpPosts[RANDOM.nextInt(numQueries)]);
                        httpResponse.close();
                        long responseTime = System.currentTimeMillis() - startTime;
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(responseTime);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    executorService.shutdown();

    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() < endTime) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:Timer0.java

public static void main(String[] argv) throws IOException {
    //+// www  . j ava 2 s . c o  m
    long t0, t1;
    System.out.println("Press return when ready");
    t0 = System.currentTimeMillis();
    int b;
    do {
        b = System.in.read();
    } while (b != '\r' && b != '\n');
    t1 = System.currentTimeMillis();
    double deltaT = t1 - t0;
    System.out.println("You took " + DecimalFormat.getInstance().format(deltaT / 1000.) + " seconds.");
    //-
}