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:Signaling.java

public static void main(String[] args) {
    try {//www  .j  av a2 s .  c om
        print("creating BooleanLock instance");
        BooleanLock ready = new BooleanLock(false);

        print("creating Signaling instance");
        new Signaling(ready);

        print("about to sleep for 3 seconds");
        Thread.sleep(3000);

        print("about to setValue to true");
        ready.setValue(true);
        print("ready.isTrue()=" + ready.isTrue());
    } catch (InterruptedException x) {
        x.printStackTrace();
    }
}

From source file:com.alibaba.dubbo.examples.merge.MergeConsumer.java

public static void main(String[] args) throws Exception {
    String config = MergeConsumer.class.getPackage().getName().replace('.', '/') + "/merge-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/* w  w w . j  a va2  s  .  co  m*/
    MergeService mergeService = (MergeService) context.getBean("mergeService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        try {
            List<String> result = mergeService.mergeResult();
            System.out.println("(" + i + ") " + result);
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.alibaba.dubbo.examples.merge.MergeConsumer2.java

public static void main(String[] args) throws Exception {
    String config = MergeConsumer2.class.getPackage().getName().replace('.', '/') + "/merge-consumer2.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//w  ww.ja  v  a  2 s. c o  m
    MergeService mergeService = (MergeService) context.getBean("mergeService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        try {
            List<String> result = mergeService.mergeResult();
            System.out.println("(" + i + ") " + result);
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();// w  ww  .  j  ava 2  s  . c om

    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(5000);
    }
}

From source file:com.alacoder.lion.rpc.springsupport.DemoRpcClient.java

@SuppressWarnings({ "resource", "unused" })
public static void main(String[] args) throws InterruptedException {

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "classpath*:lion_demo_server.xml" });
    System.out.println("server start...");

    ApplicationContext ctx = new ClassPathXmlApplicationContext(
            new String[] { "classpath:lion_demo_client.xml" });

    DemoService service = (DemoService) ctx.getBean("lionDemoReferer");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        System.out.println(service.hello("lion " + i));
        Thread.sleep(1000);
    }//from w w w.j  av a2  s . c  om
    System.out.println("lion demo is finish.");
    System.exit(0);
}

From source file:mase.MaseEvolve.java

public static void main(String[] args) throws Exception {
    File outDir = getOutDir(args);
    boolean force = Arrays.asList(args).contains(FORCE);
    if (!outDir.exists()) {
        outDir.mkdirs();// ww w.  j a v a2 s  .c o m
    } else if (!force) {
        System.out.println("Folder already exists: " + outDir.getAbsolutePath() + ". Waiting 5 sec.");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
        }
    }

    // Get config file
    Map<String, String> pars = readParams(args);

    // Copy config to outdir
    try {
        File rawConfig = writeConfig(args, pars, outDir, false);
        File destiny = new File(outDir, DEFAULT_CONFIG);
        destiny.delete();
        FileUtils.moveFile(rawConfig, new File(outDir, DEFAULT_CONFIG));
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    // JBOT INTEGRATION: copy jbot config file to the outdir
    // Does nothing when jbot is not used
    if (pars.containsKey("problem.jbot-config")) {
        File jbot = new File(pars.get("problem.jbot-config"));
        FileUtils.copyFile(jbot, new File(outDir, jbot.getName()));
    }

    // Write config to system temp file
    File config = writeConfig(args, pars, outDir, true);
    // Launch
    launchExperiment(config);
}

From source file:NewThread.java

public static void main(String args[]) {
    ThreadGroup groupA = new ThreadGroup("Group A");
    ThreadGroup groupB = new ThreadGroup("Group B");

    NewThread ob1 = new NewThread("One", groupA);
    NewThread ob2 = new NewThread("Two", groupA);
    NewThread ob3 = new NewThread("Three", groupB);
    NewThread ob4 = new NewThread("Four", groupB);

    groupA.list();/*from  ww w  .  j  a va2s .  c o  m*/
    groupB.list();
    Thread tga[] = new Thread[groupA.activeCount()];
    groupA.enumerate(tga);
    for (int i = 0; i < tga.length; i++) {
        ((NewThread) tga[i]).mysuspend();
    }

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
        System.out.println("Main thread interrupted.");
    }

    System.out.println("Resuming Group A");
    for (int i = 0; i < tga.length; i++) {
        ((NewThread) tga[i]).myresume();
    }

    try {
        ob1.join();
        ob2.join();
        ob3.join();
        ob4.join();
    } catch (Exception e) {
        System.out.println("Exception in Main thread");
    }
}

From source file:demo.wssec.server.Server.java

public static void main(String args[]) throws Exception {
    System.out.println();/*from   w  w  w  .  j  ava  2 s. c om*/
    new Server();
    System.out.println("Server ready...");

    Thread.sleep(5 * 60 * 1000);
    System.out.println("Server exiting");
    System.exit(0);
}

From source file:com.apress.prospringintegration.social.xmpp.XmppPresenceOutbound.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/spring/xmpp/xmpp-presence-outbound.xml", XmppOutbound.class);

    MessageChannel input = context.getBean("xmppOutbound", MessageChannel.class);

    Presence presence = new Presence(Presence.Type.available, "Out to lunch", 0, Presence.Mode.away);
    Message<Presence> message = MessageBuilder.withPayload(presence).build();

    input.send(message);/*from w w  w  . j a  va 2s . c  om*/

    Thread.sleep(10 * 60 * 1000);
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 56");
    final ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH);
    Rectangle clientArea = shell.getClientArea();
    bar.setBounds(clientArea.x, clientArea.y, 200, 32);
    shell.open();/*w  w w.  ja v  a2 s  .co  m*/
    final int maximum = bar.getMaximum();
    new Thread() {
        @Override
        public void run() {
            for (final int[] i = new int[1]; i[0] <= maximum; i[0]++) {
                try {
                    Thread.sleep(100);
                } catch (Throwable th) {
                }
                if (display.isDisposed())
                    return;
                display.asyncExec(() -> {
                    if (bar.isDisposed())
                        return;
                    bar.setSelection(i[0]);
                });
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}