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:eu.scape_project.pc.tika.cli.TifowaCli.java

public static void main(String[] args) {
    // Static for command line option parsing
    TifowaCli tc = new TifowaCli();
    detector = new DefaultDetector();
    CommandLineParser cmdParser = new PosixParser();
    try {/*from ww w .j  a  va2 s.c o m*/
        CommandLine cmd = cmdParser.parse(OPTIONS, args);
        if ((args.length == 0) || (cmd.hasOption(HELP_OPT))) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(Constants.USAGE, OPTIONS, true);
            System.exit(0);
        } else {
            if (cmd.hasOption(DIR_OPT) && cmd.getOptionValue(DIR_OPT) != null) {
                String dirStr = cmd.getOptionValue(DIR_OPT);
                logger.info("Directory: " + dirStr);

                // *** start timer
                long startClock = System.currentTimeMillis();

                tc.processFiles(new File(dirStr));

                // *** stop timer
                long elapsedTimeMillis = System.currentTimeMillis() - startClock;

                //  *** display the TYPE collection
                displayMyTypes(myCollection, countAllCalls, countAllGoodItems, countAllFailedItems,
                        elapsedTimeMillis);

            } else {
                logger.error("No directory given.");
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp(Constants.USAGE, OPTIONS, true);
                System.exit(1);
            }
        }
    } catch (ParseException ex) {
        logger.error("Problem parsing command line arguments.", ex);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Constants.USAGE, OPTIONS, true);
        System.exit(1);
    }
}

From source file:com.cloudhopper.sxmp.Post.java

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

    String message = "Test With @ Character";
    //String message = "Tell Twitter what you're doing!\nStd msg charges apply. Send 'stop' to quit.\nVisit twitter.com or email help@twitter.com for help.";

    StringBuilder string0 = new StringBuilder(200).append("<?xml version=\"1.0\"?>\n")
            .append("<operation type=\"submit\">\n")
            .append(" <account username=\"customer1\" password=\"password1\"/>\n")
            .append(" <submitRequest referenceId=\"MYREF102020022\">\n")
            .append("  <operatorId>75</operatorId>\n").append("  <deliveryReport>true</deliveryReport>\n")
            .append("  <sourceAddress type=\"network\">40404</sourceAddress>\n")
            .append("  <destinationAddress type=\"international\">+13135551234</destinationAddress>\n")
            .append("  <text encoding=\"ISO-8859-1\">" + HexUtil.toHexString(message.getBytes("ISO-8859-1"))
                    + "</text>\n")
            .append(" </submitRequest>\n").append("</operation>\n").append("");

    /**//from  w  w  w.  j  a  va2 s  . co  m
    //.append("<!DOCTYPE chapter PUBLIC \"-//OASIS//DTD DocBook XML//EN\" \"../dtds/docbookx.dtd\">")
    //.append("<!DOCTYPE chapter PUBLIC \"-//OASIS//DTD DocBook XML//EN\">")
    .append("<submitRequest sequenceId=\"1000\">\n")
    .append("   <!-- this is a comment -->\n")
    .append("   <account username=\"testaccount\" password=\"testpassword\"/>\n")
    .append("   <option />\n")
    .append("   <messageRequest referenceId=\"MYMESSREF\">\n")
    //.append("       <sourceAddress>+13135551212</sourceAddress>\n")
    .append("       <destinationAddress>+13135551200</destinationAddress>\n")
    .append("       <text><![CDATA[Hello World]]></text>\n")
    .append("   </messageRequest>\n")
    .append("</submitRequest>")
    .append("");
     */

    // Get target URL
    String strURL = "http://localhost:9080/api/sxmp/1.0";

    // Get file to be posted
    //String strXMLFilename = args[1];
    //File input = new File(strXMLFilename);

    HttpClient client = new DefaultHttpClient();

    long totalStart = System.currentTimeMillis();

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

        // execute request
        try {
            HttpPost post = new HttpPost(strURL);

            StringEntity entity = new StringEntity(string0.toString(), "ISO-8859-1");
            entity.setContentType("text/xml; charset=\"ISO-8859-1\"");
            post.setEntity(entity);

            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = client.execute(post, responseHandler);
            long stop = System.currentTimeMillis();

            logger.debug("----------------------------------------");
            logger.debug("Response took " + (stop - start) + " ms");
            logger.debug(responseBody);
            logger.debug("----------------------------------------");
        } finally {
            // do nothing
        }
    }

    long totalEnd = System.currentTimeMillis();

    logger.debug("Response took " + (totalEnd - totalStart) + " ms");

}

From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java

/**
 * @param args the command line arguments
 *///from  w  ww .  j a v a 2 s  .com
public static void main(String[] args) {
    int stat;
    startMs = System.currentTimeMillis();
    try {
        TimeSeriesApp me = new TimeSeriesApp();

        // decode command line and set parameters
        boolean doit = me.processArgs(args);

        // generate image
        if (doit) {
            stat = me.doPlot();
        } else {
            stat = 10;
        }
    } catch (Exception ex) {
        Logger.getLogger(TimeSeriesApp.class.getName()).log(Level.SEVERE, null, ex);
        stat = 11;
    }
    // timing info
    double elapsedSec = (System.currentTimeMillis() - startMs) / 1000.;

    System.out.format("Run time: %1$.2f sec%n", elapsedSec);
    System.exit(stat);

}

From source file:com.alibaba.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/*from  w  ww . j a va 2s .  c om*/
            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.println("Consumer Started.");
    }
}

From source file:edu.freiburg.dbis.rdd.RddExtractor.java

/**
 * @param args//from   w  ww .j a  v a2  s.c  om
 */
public static void main(String[] args) {
    String Classname = RddExtractor.class.getName();
    // Creating and parsing commandline options
    Options options = createOptions();
    CommandLineParser parser = new BasicParser();
    HelpFormatter help = new HelpFormatter();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            help.printHelp(Classname, options);
            return;
        }
        // XOR (either input-file or sparql-endpoint) --> Throw error if it is the same
        if (cmd.hasOption("i") == cmd.hasOption("e")) {
            help.printHelp(Classname, options);
            System.err.println(
                    "Use either the the option to read from an input file or (XOR) the option to send queries against an SPARQL Endpoint");
            return;
        }
        // the graph variable can only be used with the sparql-enpoint
        if ((cmd.hasOption("g") == true) && (cmd.hasOption("e") == false)) {
            help.printHelp(Classname, options);
            System.err.println(
                    "The graph variable can only be used when sending queries against a SPARQL Endpoint");
            return;
        }

    } catch (ParseException e) {
        help.printHelp(Classname, options);
        System.err.println("Command line parsing failed. Reason: " + e.getMessage());
        return;
    }

    String INPUT_FILE = cmd.getOptionValue("i");
    String OUTPUT_FILE = cmd.getOptionValue("o");
    String ENDPOINTURL = cmd.getOptionValue("e");
    String VIRTUOSO_GRAPH_NAME = cmd.getOptionValue("g");
    String WA = cmd.getOptionValue("w");
    String propertyFile = "src/main/resources/log4j.properties2";
    if (cmd.hasOption("v")) {
        propertyFile = "src/main/resources/log4j.properties";
    } else if (cmd.hasOption("l")) {
        propertyFile = cmd.getOptionValue("l");
    }
    //      String propertyFile = (cmd.hasOption("l")) ? cmd.getOptionValue("l") : "src/main/resources/log4j.properties2";

    PropertyConfigurator.configure(propertyFile);

    logger.debug("INPUT FILE  : " + INPUT_FILE);
    logger.debug("OUTPUT FILE : " + OUTPUT_FILE);
    logger.debug("ENDPOINT URL: " + ENDPOINTURL);
    logger.debug("GRAPH NAME  : " + VIRTUOSO_GRAPH_NAME);
    logger.debug("WORLD ASSUMP: " + WA);

    long start = System.currentTimeMillis();
    long end = 0;
    logger.info("Starting The Generator");
    Backend back = new Backend(INPUT_FILE, OUTPUT_FILE, ENDPOINTURL, VIRTUOSO_GRAPH_NAME, WA);
    end = System.currentTimeMillis();
    logger.info("Runtime of Generator in ms: " + (end - start));
}

From source file:gov.pnnl.cloud.KinesisApplication.java

/**
 * @param args Property file with config overrides (e.g. application name, stream name)
 * @throws IOException Thrown if we can't read properties from the specified properties file
 *//*from w w  w  .  j av a2  s. co  m*/
public static void main(String[] args) throws IOException {
    String propertiesFile = null;

    if (args.length > 1) {
        System.err.println("Usage: java " + KinesisApplication.class.getName() + " <propertiesFile>");
        System.exit(1);
    } else if (args.length == 1) {
        propertiesFile = args[0];
    }

    configure(propertiesFile);

    System.out.println("Starting " + applicationName);
    LOG.info("Running " + applicationName + " to process stream " + streamName);

    StatisticsCollection stats = new StatisticsCollection();
    StatisticsCollectionOutput statsOut = new StatisticsCollectionOutput(30000, stats);
    stats.setStatValue(Key.APPLICATION_START, System.currentTimeMillis());
    statsOut.start();

    IRecordProcessorFactory recordProcessorFactory = new KinesisRecordProcessorFactory(kafkaBrokerList, stats);
    Worker worker = new Worker(recordProcessorFactory, kinesisClientLibConfiguration);

    int exitCode = 0;
    try {
        worker.run();
    } catch (Throwable t) {
        LOG.error("Caught throwable while processing data.", t);
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:eu.scape_project.pc.droid.cli.DroidCli.java

public static void main(String[] args) {
    // Static for command line option parsing
    DroidCli tc = new DroidCli();

    CommandLineParser cmdParser = new PosixParser();
    try {//  ww w.ja v  a 2s.c  om
        CommandLine cmd = cmdParser.parse(OPTIONS, args);
        if ((args.length == 0) || (cmd.hasOption(HELP_OPT))) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(Constants.USAGE, OPTIONS, true);
            System.exit(0);
        } else {
            if (cmd.hasOption(DIR_OPT) && cmd.getOptionValue(DIR_OPT) != null) {
                String dirStr = cmd.getOptionValue(DIR_OPT);
                logger.info("Directory: " + dirStr);

                // *** start timer
                long startClock = System.currentTimeMillis();
                try {
                    tc.processFiles(new File(dirStr));

                } catch (FileNotFoundException ex) {
                    logger.error("File not found", ex);
                } catch (IOException ex) {
                    logger.error("I/O Exception", ex);
                }

                // *** stop timer
                long elapsedTimeMillis = System.currentTimeMillis() - startClock;
                logger.info("Identification finished after " + elapsedTimeMillis + " milliseconds");

            } else {
                logger.error("No directory given.");
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp(Constants.USAGE, OPTIONS, true);
                System.exit(1);
            }
        }
    } catch (ParseException ex) {
        logger.error("Problem parsing command line arguments.", ex);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Constants.USAGE, OPTIONS, true);
        System.exit(1);
    }
}

From source file:fr.inria.atlanmod.kyanos.benchmarks.CdoTraverser.java

public static void main(String[] args) {
    Options options = new Options();

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input CDO resource directory");
    inputOpt.setArgs(1);//from  w w  w.  ja v a  2  s . co m
    inputOpt.setRequired(true);

    Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS);
    inClassOpt.setArgName("CLASS");
    inClassOpt.setDescription("FQN of EPackage implementation class");
    inClassOpt.setArgs(1);
    inClassOpt.setRequired(true);

    Option repoOpt = OptionBuilder.create(REPO_NAME);
    repoOpt.setArgName("REPO_NAME");
    repoOpt.setDescription("CDO Repository name");
    repoOpt.setArgs(1);
    repoOpt.setRequired(true);

    options.addOption(inputOpt);
    options.addOption(inClassOpt);
    options.addOption(repoOpt);

    CommandLineParser parser = new PosixParser();

    try {
        CommandLine commandLine = parser.parse(options, args);

        String repositoryDir = commandLine.getOptionValue(IN);
        String repositoryName = commandLine.getOptionValue(REPO_NAME);

        Class<?> inClazz = CdoTraverser.class.getClassLoader()
                .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS));
        inClazz.getMethod("init").invoke(null);

        EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName);
        try {
            server.run();
            CDOSession session = server.openSession();
            CDOTransaction transaction = session.openTransaction();
            Resource resource = transaction.getRootResource();

            LOG.log(Level.INFO, "Start counting");
            int count = 0;
            long begin = System.currentTimeMillis();
            for (Iterator<EObject> iterator = resource.getAllContents(); iterator.hasNext(); iterator
                    .next(), count++)
                ;
            long end = System.currentTimeMillis();
            LOG.log(Level.INFO, "End counting");
            LOG.log(Level.INFO,
                    MessageFormat.format("Resource {0} contains {1} elements", resource.getURI(), count));
            LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));

            transaction.close();
            session.close();
        } finally {
            server.stop();
        }
    } catch (ParseException e) {
        MessageUtil.showError(e.toString());
        MessageUtil.showError("Current arguments: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar <this-file.jar>", options, true);
    } catch (Throwable e) {
        MessageUtil.showError(e.toString());
    }
}

From source file:edu.uci.ics.asterix.transaction.management.service.locking.LockManagerRandomUnitTest.java

public static void main(String args[]) throws ACIDException, AsterixException, IOException {
    int i;/* w w  w  .  j  a  v a 2  s  . c om*/
    //prepare configuration file
    File cwd = new File(System.getProperty("user.dir"));
    File asterixdbDir = cwd.getParentFile();
    File srcFile = new File(asterixdbDir.getAbsoluteFile(),
            "asterix-app/src/main/resources/asterix-build-configuration.xml");
    File destFile = new File(cwd, "target/classes/asterix-configuration.xml");
    FileUtils.copyFile(srcFile, destFile);

    TransactionSubsystem txnProvider = new TransactionSubsystem("nc1", null,
            new AsterixTransactionProperties(new AsterixPropertiesAccessor()));
    rand = new Random(System.currentTimeMillis());
    for (i = 0; i < MAX_NUM_OF_ENTITY_LOCK_JOB; i++) {
        System.out.println("Creating " + i + "th EntityLockJob..");
        generateEntityLockThread(txnProvider);
    }

    for (i = 0; i < MAX_NUM_OF_DATASET_LOCK_JOB; i++) {
        System.out.println("Creating " + i + "th DatasetLockJob..");
        generateDatasetLockThread(txnProvider);
    }

    for (i = 0; i < MAX_NUM_OF_UPGRADE_JOB; i++) {
        System.out.println("Creating " + i + "th EntityLockUpgradeJob..");
        generateEntityLockUpgradeThread(txnProvider);
    }
    ((LogManager) txnProvider.getLogManager()).stop(false, null);
}

From source file:dhtaccess.benchmark.LatencyMeasure.java

public static void main(String[] args) {
    boolean details = false;
    int repeats = DEFAULT_REPEATS;
    boolean doPut = true;

    // parse options
    Options options = new Options();
    options.addOption("h", "help", false, "print help");
    options.addOption("d", "details", false, "requests secret hash and TTL");
    options.addOption("r", "repeats", true, "number of requests");
    options.addOption("n", "no-put", false, "does not put");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//  w  ww  .  j  av a 2s .c  o  m
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println("There is an invalid option.");
        e.printStackTrace();
        System.exit(1);
    }

    String optVal;
    if (cmd.hasOption('h')) {
        usage(COMMAND);
        System.exit(1);
    }
    if (cmd.hasOption('d')) {
        details = true;
    }
    optVal = cmd.getOptionValue('r');
    if (optVal != null) {
        repeats = Integer.parseInt(optVal);
    }
    if (cmd.hasOption('n')) {
        doPut = false;
    }

    args = cmd.getArgs();

    // parse arguments
    if (args.length < 1) {
        usage(COMMAND);
        System.exit(1);
    }

    // prepare for RPC
    int numAccessor = args.length;
    DHTAccessor[] accessorArray = new DHTAccessor[numAccessor];
    try {
        for (int i = 0; i < numAccessor; i++) {
            accessorArray[i] = new DHTAccessor(args[i]);
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
        System.exit(1);
    }

    // generate key prefix
    Random rnd = new Random(System.currentTimeMillis());

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < KEY_PREFIX_LENGTH; i++) {
        sb.append((char) ('a' + rnd.nextInt(26)));
    }
    String keyPrefix = sb.toString();
    String valuePrefix = VALUE_PREFIX;

    // benchmarking
    System.out.println("Repeats " + repeats + " times.");

    if (doPut) {
        System.out.println("Putting: " + keyPrefix + "<number>");

        for (int i = 0; i < repeats; i++) {
            byte[] key = null, value = null;
            try {
                key = (keyPrefix + i).getBytes(ENCODE);
                value = (valuePrefix + i).getBytes(ENCODE);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                System.exit(1);
            }

            int accIndex = rnd.nextInt(numAccessor);
            DHTAccessor acc = accessorArray[accIndex];
            acc.put(key, value, TTL);
        }
    }

    System.out.println("Benchmarking by getting.");

    int count = 0;
    long startTime = System.currentTimeMillis();

    if (details) {
        for (int i = 0; i < repeats; i++) {
            byte[] key = null;
            try {
                key = (keyPrefix + i).getBytes(ENCODE);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                System.exit(1);
            }

            int accIndex = rnd.nextInt(numAccessor);
            DHTAccessor acc = accessorArray[accIndex];
            Set<DetailedGetResult> valueSet = acc.getDetails(key);
            if (valueSet != null && !valueSet.isEmpty()) {
                count++;
            }
        }
    } else {
        for (int i = 0; i < repeats; i++) {
            byte[] key = null;
            try {
                key = (keyPrefix + i).getBytes(ENCODE);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                System.exit(1);
            }

            int accIndex = rnd.nextInt(numAccessor);
            DHTAccessor acc = accessorArray[accIndex];
            Set<byte[]> valueSet = acc.get(key);
            if (valueSet != null && !valueSet.isEmpty()) {
                count++;
            }
        }
    }

    System.out.println(System.currentTimeMillis() - startTime + " msec.");
    System.out.println("Rate of successful gets: " + count + " / " + repeats);
}