Example usage for java.lang Thread sleep

List of usage examples for java.lang Thread sleep

Introduction

In this page you can find the example usage for java.lang Thread sleep.

Prototype

public static native void sleep(long millis) throws InterruptedException;

Source Link

Document

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers.

Usage

From source file:com.pivotal.gemfire.tools.pulse.testbed.driver.TomcatHelper.java

public static void main(String[] args) throws Exception {
    String host = InetAddress.getLocalHost().getHostAddress();
    int port = 8080;
    String path = "/tushark1/code-checkout/tools/Pulse/trunk/build-artifacts/linux/dist/pulse-7.0.1.RC1.war";
    String context = "/pulse";
    System.setProperty("pulse.propMockDataUpdaterClass",
            "com.pivotal.gemfire.tools.pulse.testbed.PropMockDataUpdater");
    Tomcat tomcat = TomcatHelper.startTomcat("localhost", port, context, path);
    Thread.sleep(30000);
    System.out.println("Sleep completed");
    System.out.println("Exiting ....");
    tomcat.stop();/*from   ww  w.  j  a v a 2s.  c  om*/
    tomcat.destroy();
}

From source file:com.pivotal.gemfire.tools.pulse.tests.TomcatHelper.java

public static void main(String[] args) throws Exception {
    String host = InetAddress.getLocalHost().getHostAddress();
    int port = 9090;
    String path = "D:/springsource/springsourceWS/VMware-Pulse-cheetah-dev-jun13/build-artifacts/win/dist/pulse-7.0.1.war";
    String context = "/pulse";
    System.setProperty("pulse.propMockDataUpdaterClass",
            "com.pivotal.gemfire.tools.pulse.testbed.PropMockDataUpdater");
    Tomcat tomcat = TomcatHelper.startTomcat("localhost", port, context, path);
    Thread.sleep(30000);
    System.out.println("Sleep completed");
    System.out.println("Exiting ....");
    tomcat.stop();//w w w.  ja v a2  s.co  m
    tomcat.destroy();
}

From source file:edu.stanford.junction.addon.JunctionServiceFactory.java

public static void main(String[] argv) {
    String switchboard = "prpl.stanford.edu";

    JunctionService waiter = new JunctionServiceFactory();
    waiter.register(switchboard);//w  w w.  j  a  v a 2  s.  c  o m
    while (true) {
        try {
            Thread.sleep(500000);
        } catch (Exception e) {
        }
    }
}

From source file:com.cloudera.impala.testutil.SentryServicePinger.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    // Parse command line options to get config file path.
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config_file")
            .withDescription("Absolute path to a sentry-site.xml config file (string)").hasArg()
            .withArgName("CONFIG_FILE").isRequired().create('c'));
    options.addOption(OptionBuilder.withLongOpt("num_pings")
            .withDescription("Max number of pings to try before failing (int)").hasArg().isRequired()
            .withArgName("NUM_PINGS").create('n'));
    options.addOption(//from ww  w .ja  v  a  2s  .  c  o  m
            OptionBuilder.withLongOpt("sleep_secs").withDescription("Time (s) to sleep between pings (int)")
                    .hasArg().withArgName("SLEEP_SECS").create('s'));
    BasicParser optionParser = new BasicParser();
    CommandLine cmdArgs = optionParser.parse(options, args);

    SentryConfig sentryConfig = new SentryConfig(cmdArgs.getOptionValue("config_file"));
    int numPings = Integer.parseInt(cmdArgs.getOptionValue("num_pings"));
    int maxPings = numPings;
    int sleepSecs = Integer.parseInt(cmdArgs.getOptionValue("sleep_secs"));

    sentryConfig.loadConfig();
    while (numPings > 0) {
        SentryPolicyService policyService = new SentryPolicyService(sentryConfig);
        try {
            policyService.listAllRoles(new User(System.getProperty("user.name")));
            LOG.info("Sentry Service ping succeeded.");
            System.exit(0);
        } catch (Exception e) {
            LOG.error(String.format("Error issing RPC to Sentry Service (attempt %d/%d): ",
                    maxPings - numPings + 1, maxPings), e);
            Thread.sleep(sleepSecs * 1000);
        }
        --numPings;
    }
    System.exit(1);
}

From source file:com.chschmid.pilight.server.PILight.java

public static void main(String args[]) throws Exception {
    // Application Title
    System.out.println(TITLE);/*from  ww w  .ja  va  2 s . co m*/

    // Apache CLI Parser
    Options options = getCLIOptions();
    CommandLineParser parser = new PosixParser();

    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("c"))
            cli = true;
        if (line.hasOption("d"))
            DEBUG = true;
        if (line.hasOption("h")) {
            printHelp();
            return;
        }
    } catch (ParseException exp) {
        System.out.println(PILIGHT + ": " + exp.getMessage());
        System.out.println(ERROR_CLI);
        return;
    }

    // Init BoosterPack and check if SPI and RF work properly
    RFBoosterPack rf = new RFBoosterPack();

    if (rf.getSPIStatus() != RFBoosterPack.STATUS_SPI_INITIALIZED) {
        System.out.println(ERROR_SPI);
        return;
    }
    if (rf.getRFStatus() != RFBoosterPack.STATUS_RF_INITIALIZED) {
        System.out.println(ERROR_RF);
        return;
    }

    // Initialize nicer interface
    PiLightInterface light = new PiLightInterface(rf);
    try {
        Thread.sleep(10);
    } catch (InterruptedException e) {
    }

    if (cli)
        simpleCommandLineInterface(light);
    else
        startServers(light);
}

From source file:PinotResponseTime.java

public static void main(String[] args) throws Exception {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        HttpPost post = new HttpPost("http://localhost:8099/query");
        CloseableHttpResponse res;//from   w w w .j  ava 2  s  .c  om

        if (STORE_RESULT) {
            File dir = new File(RESULT_DIR);
            if (!dir.exists()) {
                dir.mkdirs();
            }
        }

        int length;

        // Make sure all segments online
        System.out.println("Test if number of records is " + RECORD_NUMBER);
        post.setEntity(new StringEntity("{\"pql\":\"select count(*) from tpch_lineitem\"}"));
        while (true) {
            System.out.print('*');
            res = client.execute(post);
            boolean valid;
            try (BufferedInputStream in = new BufferedInputStream(res.getEntity().getContent())) {
                length = in.read(BUFFER);
                valid = new String(BUFFER, 0, length, "UTF-8").contains("\"value\":\"" + RECORD_NUMBER + "\"");
            }
            res.close();
            if (valid) {
                break;
            } else {
                Thread.sleep(5000);
            }
        }
        System.out.println("Number of Records Test Passed");

        // Start Benchmark
        for (int i = 0; i < QUERIES.length; i++) {
            System.out.println(
                    "--------------------------------------------------------------------------------");
            System.out.println("Start running query: " + QUERIES[i]);
            post.setEntity(new StringEntity("{\"pql\":\"" + QUERIES[i] + "\"}"));

            // Warm-up Rounds
            System.out.println("Run " + WARMUP_ROUND + " times to warm up cache...");
            for (int j = 0; j < WARMUP_ROUND; j++) {
                res = client.execute(post);
                if (!isValid(res, null)) {
                    System.out.println("\nInvalid Response, Sleep 20 Seconds...");
                    Thread.sleep(20000);
                }
                res.close();
                System.out.print('*');
            }
            System.out.println();

            // Test Rounds
            int[] time = new int[TEST_ROUND];
            int totalTime = 0;
            int validIdx = 0;
            System.out.println("Run " + TEST_ROUND + " times to get average time...");
            while (validIdx < TEST_ROUND) {
                long startTime = System.currentTimeMillis();
                res = client.execute(post);
                long endTime = System.currentTimeMillis();
                boolean valid;
                if (STORE_RESULT && validIdx == 0) {
                    valid = isValid(res, RESULT_DIR + File.separator + i + ".json");
                } else {
                    valid = isValid(res, null);
                }
                if (!valid) {
                    System.out.println("\nInvalid Response, Sleep 20 Seconds...");
                    Thread.sleep(20000);
                    res.close();
                    continue;
                }
                res.close();
                time[validIdx] = (int) (endTime - startTime);
                totalTime += time[validIdx];
                System.out.print(time[validIdx] + "ms ");
                validIdx++;
            }
            System.out.println();

            // Process Results
            double avgTime = (double) totalTime / TEST_ROUND;
            double stdDev = 0;
            for (int temp : time) {
                stdDev += (temp - avgTime) * (temp - avgTime) / TEST_ROUND;
            }
            stdDev = Math.sqrt(stdDev);
            System.out.println("The average response time for the query is: " + avgTime + "ms");
            System.out.println("The standard deviation is: " + stdDev);
        }
    }
}

From source file:UtilTimerDemo.java

public static void main(String[] args) {
    // Start and run a fixed-delay timer
    timer = new Timer();
    startTime = prevTime = System.currentTimeMillis();
    System.out.println("Fixed Delay Times");
    timer.schedule(new UtilTimerDemo(), DELAY, DELAY);

    // Sleep long enough to let the first timer finish
    try {/*w  w  w . j av  a2  s  .  c o  m*/
        Thread.sleep(DURATION * 2);
    } catch (Exception e) {
    }

    // Start and run a fixed-rate timer
    timer = new Timer();
    startTime = prevTime = System.currentTimeMillis();
    System.out.println("Fixed Rate Times");
    timer.scheduleAtFixedRate(new UtilTimerDemo(), DELAY, DELAY);
}

From source file:SwingTimerDemo.java

public static void main(String[] args) {
    // Run a default fixed-delay timer
    timer = new Timer(DELAY, new SwingTimerDemo());
    startTime = prevTime = System.currentTimeMillis();
    System.out.println("Fixed Delay Times");
    timer.start();/*from   w w  w  .ja v  a 2 s  .  co  m*/

    // Sleep for long enough that the first timer ends
    try {
        Thread.sleep(DURATION * 2);
    } catch (Exception e) {
    }

    // Run a timer with no coalescing to get fixed-rate behavior
    timer = new Timer(DELAY, new SwingTimerDemo());
    startTime = prevTime = System.currentTimeMillis();
    timer.setCoalesce(false);
    System.out.println("\nFixed Rate Times");
    timer.start();

}

From source file:com.jmstoolkit.pipeline.Pipeline.java

/**
 *
 * @param args the command line arguments
 *///www  . j  av a 2s.c  o  m
public static void main(final String[] args) {
    // Have to use System.out as logging is configured by Spring
    // application context.
    try {
        Settings.loadSystemSettings("jndi.properties");
        Settings.loadSystemSettings("app.properties");
    } catch (JTKException ex) {
        System.out.println("Failed to load application settings");
        System.out.println(JTKException.formatException(ex));
        System.exit(1);
    }

    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
            "/logging-context.xml", "/infrastructure-context.xml", "/mdb-context.xml", "/jmx-context.xml" });
    applicationContext.start();

    final DefaultMessageListenerContainer dmlc = (DefaultMessageListenerContainer) applicationContext
            .getBean("listenerContainer");
    if (dmlc != null) {
        dmlc.start();
        final Pipeline pipeline = (Pipeline) applicationContext.getBean("pipelineService");
        // enable access to the original application context
        pipeline.setApplicationContext(applicationContext);

        // Insure that the Pipeline loads configuration files AFTER
        // the listenerContainer is running.
        while (!dmlc.isRunning()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
        }
        pipeline.loadPlugins();
        pipeline.sendProperties();

        // Keep thread alive
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
        }
    }
}

From source file:webdriver.test.BasicHttpServer.java

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify HTTP document root directory as ");
        System.err.println("a argument relative to the run directory.");
        Thread.sleep(10);
        System.exit(1);/*from  w  w  w. ja v  a 2  s .  c o  m*/
    }
    Thread t = new RequestListenerThread(8001, args[0]);
    t.setDaemon(false);
    t.start();
}