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:io.reign.examples.PresenceServiceExample.java

public static void main(String[] args) throws Exception {
    /** init and start reign using builder **/
    Reign reign = Reign.maker().zkClient("localhost:2181", 30000).pathCache(1024, 8).get();
    reign.start();//from   w w  w.ja v  a  2  s .  c  om

    /** presence service example **/
    presenceServiceExample(reign);

    /** sleep to allow examples to run for a bit **/
    Thread.sleep(600000);

    /** shutdown reign **/
    reign.stop();

    /** sleep a bit to observe observer callbacks **/
    Thread.sleep(10000);
}

From source file:com.alibaba.dubbo.examples.cache.CacheConsumer.java

public static void main(String[] args) throws Exception {
    String config = CacheConsumer.class.getPackage().getName().replace('.', '/') + "/cache-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//ww  w  .  ja v a 2 s  .c o m

    CacheService cacheService = (CacheService) context.getBean("cacheService");

    // ?(?)
    String fix = null;
    for (int i = 0; i < 5; i++) {
        String result = cacheService.findCache("0");
        if (fix == null || fix.equals(result)) {
            System.out.println("OK: " + result);
        } else {
            System.err.println("ERROR: " + result);
        }
        fix = result;
        Thread.sleep(500);
    }

    // LRU?cache.size10001001
    for (int n = 0; n < 1001; n++) {
        String pre = null;
        for (int i = 0; i < 10; i++) {
            String result = cacheService.findCache(String.valueOf(n));
            if (pre != null && !pre.equals(result)) {
                System.err.println("ERROR: " + result);
            }
            pre = result;
        }
    }

    // LRU
    String result = cacheService.findCache("0");
    System.out.println("OK--->: " + result);
    if (fix != null && !fix.equals(result)) {
        System.out.println("OK: " + result);
    } else {
        System.err.println("ERROR: " + result);
    }
}

From source file:demo.vmware.app.JmxAgent.java

/**
 * @param args//ww w  . j  a va2s .c  o m
 */
public static void main(String[] args) throws Exception {
    String resource[] = { "spring-cache-jmxagent.xml" };
    ClassPathXmlApplicationContext mainContext = new ClassPathXmlApplicationContext(resource, false);
    mainContext.setValidating(true);
    mainContext.refresh();
    LOG.debug("Done attempting to start jmx agent");
    Thread.sleep(Long.MAX_VALUE);
}

From source file:com.apress.prospringintegration.messaging.rabbitmq.jms.adapter.TicketReporterMain.java

public static void main(String[] args) throws Throwable {
    String contextName = "ticket-reporter.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//from   w w w.  ja va  2s.c o m

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    RabbitAdmin admin = applicationContext.getBean(RabbitAdmin.class);

    Queue queue = applicationContext.getBean(Queue.class);

    admin.declareQueue(queue);

    while (true) {
        List<Ticket> tickets = ticketGenerator.createTickets();
        for (Ticket ticket : tickets) {
            problemReporter.openTicket(ticket);
        }

        Thread.sleep(5000);
    }
}

From source file:MouseEventPost.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final Button button = new Button(shell, SWT.NONE);
    button.setSize(100, 100);/*from  w  w w.  ja v a2 s.c  om*/
    button.setText("Click");
    shell.pack();
    shell.open();
    button.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")");
        }
    });
    final Point pt = display.map(shell, null, 50, 50);
    new Thread() {
        Event event;

        public void run() {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event = new Event();
            event.type = SWT.MouseMove;
            event.x = pt.x;
            event.y = pt.y;
            display.post(event);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.apache.camel.example.CamelFileSizeCBRMain.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "META-INF/spring/camel-file-size-cbr.xml");

    final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);

    for (int i = 1; i < SIZE; i++) {
        producer.sendBodyAndHeader("seda:allFiles", getPayload(i), Exchange.FILE_NAME, i + ".txt");
    }/*from   w  w  w.ja va 2 s  .  c om*/

    Thread.sleep(100000);
    context.stop();
}

From source file:XSplineFun.java

public static void main(String[] av) {
        Frame f = new Frame("Spline Fun");
        XSplineFun xf = new XSplineFun();
        xf.init_splines();//from  w  w  w. j av  a2 s .  c o m
        f.add(xf);
        while (true)
            try {
                xf.move_splines();
                Thread.sleep(150); // msec
            } catch (Exception e) {
                System.out.println(e);
            }
    }

From source file:fr.irit.smac.libs.tooling.examples.plot.local.LocalChart.java

public static void main(String[] args) {

    // First, we inform the server that the chart "Layer" must be of type
    // PLOT/*from w  w  w.  ja  va 2 s . c o  m*/
    AgentPlot.getServer().configChart("Layer", ChartType.PLOT);

    // Add plots to the chart "Layer" for serie #0
    AgentPlot.getChart("Layer").add(1, 2);
    AgentPlot.getChart("Layer").add(2, 2.5);
    AgentPlot.getChart("Layer").add(2, 3);

    // Add plots to the chart "Layer" for serie "My serie"
    AgentPlot.getChart("Layer").add("My serie", 21, 2);
    AgentPlot.getChart("Layer").add("My serie", 12, 2.5);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // Add plots to the chart "My Chart" which will be created during this
    // call
    AgentPlot.getChart("My chart").add(2, 3);
    AgentPlot.getChart("My chart").add(3, 3);
    AgentPlot.getChart("My chart").add(3, 4);

    // Access the JFreeChart object (only from the server side)
    JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart();
    // Change its title
    chart.getTitle().setText("New title");

    // Close chart
    // AgentPlot.getChart("My chart").close();
    // AgentPlot.getChart("Layer").close();
}

From source file:org.apache.camel.example.cxf.provider.Server.java

public static void main(String args[]) throws Exception {
    Server server = new Server();
    System.out.println("Server ready...");

    Thread.sleep(5 * 60 * 1000);
    System.out.println("Server exiting");
    server.stop();//from   w  w  w  .ja  va 2s.c o  m
    System.exit(0);
}

From source file:com.github.liyp.test.TestMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // add a shutdown hook to stop the server
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override//w  ww .ja v a2s . c  o  m
        public void run() {
            System.out.println("########### shoutdown begin....");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("########### shoutdown end....");
        }
    }));

    System.out.println(args.length);
    Iterator<String> iterator1 = IteratorUtils
            .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" });
    Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" });

    Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2);

    System.out.println("==================");

    Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            System.out.println("xx:" + arg0.toString());
            String str = (String) arg0;
            return str.matches("([a-z]|[A-Z]){2}");
        }
    });
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }

    System.out.println("===================");

    System.out.println("asas".matches("[a-z]{4}"));

    System.out.println("Y".equals(null));

    System.out.println(String.format("%02d", 1000L));

    System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ",")));

    System.out.println(new ArrayList<String>().toString());

    JSONObject json = new JSONObject("{\"keynull\":null}");
    json.put("bool", false);
    json.put("keya", "as");
    json.put("key2", 2212222222222222222L);
    System.out.println(json);
    System.out.println(json.get("keynull").equals(null));

    String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1,
            1);
    System.out.println(a.getBytes().length);

    System.out.println(new String[] { "a", "b" });

    System.out.println(new JSONArray("[\"aa\",\"\"]"));

    String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10));
    System.out.println(data.getBytes().length);

    System.out.println(ArrayUtils.toString("1|2| 3|  333||| 3".split("\\|")));

    JSONObject j1 = new JSONObject("{\"a\":\"11111\"}");
    JSONObject j2 = new JSONObject(j1.toString());
    j2.put("b", "22222");
    System.out.println(j1 + " | " + j2);

    System.out.println("======================");

    String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher("2015-12-28 15:46:14  _NC250_MD:motion de\n");
    String eventDate = matcher.find() ? matcher.group() : "";

    System.out.println(eventDate);
}