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:hd3gtv.embddb.MainClass.java

public static void main(String[] args) throws Exception {
    Security.addProvider(new BouncyCastleProvider());

    PoolManager poolmanager = new PoolManager("test");
    poolmanager.startLocalServers();/*from   w  w  w.j  a  v a  2 s .  co  m*/

    // TODO manage white/black range addr list for autodiscover

    Thread.sleep(50);

    Properties conf = new Properties();
    conf.load(FileUtils.openInputStream(new File("conf.properties")));

    poolmanager.setBootstrapPotentialNodes(
            importConf(poolmanager, conf, poolmanager.getProtocol().getDefaultTCPPort()));
    poolmanager.connectToBootstrapPotentialNodes("Startup");

    Thread.sleep(50);

    poolmanager.startConsole();
}

From source file:InvokeExample.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.add(good);/*from   w  ww  .ja  v a2  s  .  c o  m*/
    p.add(bad);
    p.add(bad2);

    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(p, BorderLayout.CENTER);
    c.add(resultLabel, BorderLayout.SOUTH);

    good.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            setEnabled(false);
            Thread worker = new Thread() {
                public void run() {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }

                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            resultLabel.setText("Ready");
                            setEnabled(true);
                        }
                    });
                }
            };
            worker.start();
        }
    });

    bad.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            setEnabled(false);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
            }
            resultLabel.setText("Ready");
            setEnabled(true);
        }
    });

    bad2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . . ");
            setEnabled(false);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(5000); // Dispatch thread is starving!
                    } catch (InterruptedException ex) {
                    }

                    resultLabel.setText("Ready");
                    setEnabled(true);
                }
            });
        }
    });

    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:org.eclipse.swt.snippets.Snippet146.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 146");
    final Text text = new Text(shell, SWT.BORDER);
    text.setSize(text.computeSize(150, SWT.DEFAULT));
    shell.pack();/*  w w w. j ava2  s  .  c o m*/
    shell.open();
    new Thread() {
        @Override
        public void run() {
            // wait for shell to be opened
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }

            String string = "Love the method.";
            for (int i = 0; i < string.length(); i++) {
                char ch = string.charAt(i);
                boolean shift = Character.isUpperCase(ch);
                ch = Character.toLowerCase(ch);
                if (shift) {
                    Event event = new Event();
                    event.type = SWT.KeyDown;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
                Event event = new Event();
                event.type = SWT.KeyDown;
                event.character = ch;
                display.post(event);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                event.type = SWT.KeyUp;
                display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (shift) {
                    event = new Event();
                    event.type = SWT.KeyUp;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Deadlock.java

public static void main(String[] args) {
    final Deadlock obj1 = new Deadlock("Thread 1");
    final Deadlock obj2 = new Deadlock("Thread 2");

    Runnable runA = new Runnable() {
        public void run() {
            obj1.checkOther(obj2);//from  w w w . ja v a 2s.c om
        }
    };

    Thread thread = new Thread(runA, "A");
    thread.start();

    try {
        Thread.sleep(200);
    } catch (InterruptedException x) {
    }

    Runnable runB = new Runnable() {
        public void run() {
            obj2.checkOther(obj1);
        }
    };

    Thread threadB = new Thread(runB, "B");
    threadB.start();

    try {
        Thread.sleep(5000);
    } catch (InterruptedException x) {
    }

    threadPrint("finished sleeping");

    threadPrint("about to interrupt() threadA");
    thread.interrupt();

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

    threadPrint("about to interrupt() threadB");
    threadB.interrupt();

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

    threadPrint("did that break the deadlock?");
}

From source file:sample.TimeStamp.java

public static void main(String[] args) throws InterruptedException {
    LocalTaskLauncher launcher = new LocalTaskLauncher(new LocalDeployerProperties());
    String timestampId = launcher.launch(createAppDeploymentRequest("timestamp-task"));
    for (int i = 0; i < 50; i++) {
        Thread.sleep(100);
        System.out.println("timestamp: " + launcher.status(timestampId));
    }/* w w  w  . j a  v a2s . c om*/
    // timestamp completes quickly, but we can 'cancel' the running task
    launcher.cancel(timestampId);
    System.out.println("timestamp after cancel: " + launcher.status(timestampId));
}

From source file:Beep.java

public static void main(String[] args) {
    // In terminal-based applications, this is a non-portable, unreliable
    // way to sound the terminal bell (if there is one) and get the
    // user's attention. \u0007 is the ASCII BEL or Ctrl-G character.
    System.out.println("BEEP\u0007!");

    // For applications that can use AWT, there is another way
    // to ring the bell.
    String[] words = new String[] { "Shave ", "and ", "a ", "hair", "cut ", "two ", "bits." };
    int[] pauses = new int[] { 300, 150, 150, 250, 450, 250, 1 };

    for (int i = 0; i < pauses.length; i++) {
        // Ring the bell using AWT
        java.awt.Toolkit.getDefaultToolkit().beep();
        System.out.print(words[i]);
        System.out.flush();/*from  w  w w  .j  a v a2s  .c om*/
        // Wait a while before beeping again.
        try {
            Thread.sleep(pauses[i]);
        } catch (InterruptedException e) {
        }
    }
    System.out.println();
}

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

public static void main(String[] args) throws Exception {
    String resource[] = { "spring-cache-client-core.xml", "spring-cache-client-cq-only.xml" };
    ClassPathXmlApplicationContext mainContext = new ClassPathXmlApplicationContext(resource, false);
    mainContext.setValidating(true);/*from   ww w . j  a v  a 2s  .  c  o m*/
    mainContext.refresh();

    LOG.info("awaiting query callback");
    Thread.sleep(Long.MAX_VALUE);

}

From source file:com.apress.prospringintegration.serviceactivator.Main.java

public static void main(String[] args) throws Exception {
    String contextName = "service-activator.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*ww  w  .  j a  va 2  s .c o m*/

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

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

        Thread.sleep(500);
    }
}

From source file:demo.HttpIntegrationApplication.java

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = SpringApplication.run(HttpIntegrationApplication.class);
    Thread.sleep(2000);
    MessageChannel channel = ctx.getBean("input", MessageChannel.class);
    channel.send(MessageBuilder/* w  w  w .j a va2  s.  c om*/
            .withPayload("{\"userId\": \"invalid@mail.com\",\"password\": \"wrongpassword\"}").build());
}

From source file:com.dangdang.config.service.easyzk.demo.spring.MainEntrance.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = null;
    try {/*from  w  w w .  j  ava2  s .  c o  m*/
        context = new ClassPathXmlApplicationContext("classpath:config-toolkit-simple.xml");
        context.registerShutdownHook();
        context.start();

        ExampleBeanWithConfigNode bean = context.getBean(ExampleBeanWithConfigNode.class);
        while (true) {
            bean.someMethod();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                //
            }
        }
    } finally {
        if (context != null) {
            context.close();
        }
    }
}