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:mjg.spring.Demo.java

public static void main(String[] args) {
    ApplicationContext ctx = new FileSystemXmlApplicationContext("resources/applicationContext.xml");
    Evaluator e = null;//from ww w  .  jav a  2s  .c  o m
    boolean ok;

    for (int i = 0; i < 10; i++) {
        e = (Evaluator) ctx.getBean("groovyEvaluator");
        ok = e.approve(null);
        System.out.println(ok ? "approved" : "denied");

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
    }

    ((FileSystemXmlApplicationContext) ctx).close();
}

From source file:InnerSelfRunMain.java

public static void main(String[] args) {
    InnerSelfRunMain sr = new InnerSelfRunMain();

    try {// w w  w  .ja  va  2s  .  c o  m
        Thread.sleep(3000);
    } catch (InterruptedException x) {
    }
    sr.stopRequest();
}

From source file:demo.hw.server.SpringServer.java

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

    Thread.sleep(5 * 60 * 1000);
    System.out.println("Server exiting");
    System.exit(0);//from   w  ww. j av a2  s .c  om
}

From source file:com.surveypanel.form.test.Runner.java

/**
 * @param args/*from w  w w  .  ja v a  2s .  c  om*/
 */
public static void main(String[] args) {
    try {
        init(surveyId);
        Thread[] runners = new Thread[100];
        for (int j = 0; j < runners.length; j++) {
            runners[j] = new Thread(new FormRun(formFactory, jsManager, surveyId));
        }
        for (Thread thread : runners) {
            thread.start();
        }
        Thread.sleep(1000);
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:net.ab0oo.aprs.clients.JmsBroker.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("web/WEB-INF/classes/broker.xml"));
    factory.getBean("broker");
    System.out.println("JMS Broker starting up");
    while (true) {
        try {//  www.  ja  v  a2 s. c o m
            Thread.sleep(10000);
        } catch (InterruptedException iex) {

        }
    }
}

From source file:EarlyReturn.java

public static void main(String[] args) {
    try {/*from  ww  w.j  av  a2s.  c  o m*/
        final EarlyReturn er = new EarlyReturn(0);

        Runnable r = new Runnable() {
            public void run() {
                try {
                    Thread.sleep(1500);
                    er.setValue(2);
                    Thread.sleep(500);
                    er.setValue(3);
                    Thread.sleep(500);
                    er.setValue(4);
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        };

        Thread t = new Thread(r);
        t.start();

        System.out.println("waitUntilAtLeast(5, 3000)");
        long startTime = System.currentTimeMillis();
        boolean retVal = er.waitUntilAtLeast(5, 3000);
        long elapsedTime = System.currentTimeMillis() - startTime;

        System.out.println(elapsedTime + " ms, retVal=" + retVal);
    } catch (InterruptedException ix) {
        ix.printStackTrace();
    }
}

From source file:com.fileanalyzer.main.Main.java

public static void main(String[] args) throws IOException {
    FileAnalyzer fl = null;//w  w  w  . j  av  a  2  s  .  com
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
        Configuration conf = (Configuration) ctx.getBean("configuration");
        fl = (FileAnalyzer) ctx.getBean("fileAnalyzer");
        if (args.length == 3 && args[1].equalsIgnoreCase("s")) {
            log.info("Added file id: " + fl.analizeString(args[0], args[2]));
        } else if (args.length == 2 && args[1].equalsIgnoreCase("a")) {
            fl.analizeFile(args[0], true);
        } else if (args.length == 1)
            fl.analizeFile(args[0], false);
        else {
            log.info(conf.getWrongParams());
            Thread.sleep(3000);
            System.exit(1);
        }
        log.info("Press any key to exit...");
        System.in.read();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (fl != null) {
            fl.shutDown();
        }
        System.exit(0);
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame parentFrame = new JFrame();
    parentFrame.setSize(500, 150);//ww w .  j ava 2 s . c  om
    JLabel jl = new JLabel();
    jl.setText("Count : 0");

    parentFrame.add(BorderLayout.CENTER, jl);
    parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parentFrame.setVisible(true);

    final JDialog dlg = new JDialog(parentFrame, "Progress Dialog", true);
    JProgressBar dpb = new JProgressBar(0, 500);
    dlg.add(BorderLayout.CENTER, dpb);
    dlg.add(BorderLayout.NORTH, new JLabel("Progress..."));
    dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dlg.setSize(300, 75);
    dlg.setLocationRelativeTo(parentFrame);

    Thread t = new Thread(new Runnable() {
        public void run() {
            dlg.setVisible(true);
        }
    });
    t.start();
    for (int i = 0; i <= 500; i++) {
        jl.setText("Count : " + i);
        dpb.setValue(i);
        if (dpb.getValue() == 500) {
            dlg.setVisible(false);
            System.exit(0);

        }
        try {
            Thread.sleep(25);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    dlg.setVisible(true);
}

From source file:com.bt.aloha.batchtest.JmxScenarioRunner.java

public static void main(String[] args) {
    while (true)/* w  w  w  . j ava 2s  . com*/
        try {
            log.info("Sleeping...");
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
}

From source file:com.alibaba.dubbo.examples.heartbeat.HeartbeatConsumer.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            HeartbeatConsumer.class.getPackage().getName().replace('.', '/') + "/heartbeat-consumer.xml");
    context.start();/* www . ja va  2 s .co  m*/
    HelloService hello = (HelloService) context.getBean("helloService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        System.out.println(hello.sayHello("kimi-" + i));
        Thread.sleep(10000);
    }
}