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:org.smartfrog.services.anubis.partition.test.controller.gui.PartitionManagerUiConfiguration.java

public static void main(String[] argv) throws InterruptedException {
    new AnnotationConfigApplicationContext(PartitionManagerUiConfiguration.class);
    while (true) {
        Thread.sleep(50000);
    }//from w  w w  .j a  v  a2  s  .c  om
}

From source file:ca.brood.tunneller.Tunneller.java

public static void main(String[] args) {
    //For testing
    Tunneller.windowsService(new String[0]);

    try {//from  w w w  .j  a  va  2 s.c  o m
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //To stop, uncomment this:
    String[] stop = new String[1];
    stop[0] = "stop";
    Tunneller.windowsService(stop);
}

From source file:example.browser.Producer.java

public static void main(String[] args) {
    String url = BROKER_URL;
    if (args.length > 0) {
        url = args[0].trim();/*from   w  w w.j a  v a 2  s  .c om*/
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url);
    Connection connection = null;

    try {

        connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("test-queue");
        MessageProducer producer = session.createProducer(destination);

        for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
            TextMessage message = session.createTextMessage("Message #" + i);
            System.out.println("Sending message #" + i);
            producer.send(message);
            Thread.sleep(DELAY);
        }

        producer.close();
        session.close();

    } catch (Exception e) {
        System.out.println("Caught exception!");
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                System.out.println("Could not close an open connection...");
            }
        }
    }
}

From source file:SunAudioClip.java

public static void main(String args[]) throws Exception {
    URL url1 = new URL("http://localhost:8080/audio/1.au");
    URL url2 = new URL("http://localhost:8080/audio/2.au");
    SunAudioClip sac1 = new SunAudioClip(url1);
    SunAudioClip sac2 = new SunAudioClip(url2);
    SunAudioClip sac3 = new SunAudioClip("1.au");
    sac1.play();//from   ww  w. j  av  a 2  s . c  o  m
    sac2.loop();
    sac3.play();
    try { // Delay for loop
        Thread.sleep(2000);
    } catch (InterruptedException ie) {
    }
    sac2.stop();
}

From source file:example.topic.durable.Publisher.java

public static void main(String[] args) {
    String url = BROKER_URL;
    if (args.length > 0) {
        url = args[0].trim();/*from  w  w w. j  av  a 2  s .  c o m*/
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url);
    Connection connection = null;

    try {

        connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createTopic("test-topic");
        MessageProducer producer = session.createProducer(destination);

        for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
            TextMessage message = session.createTextMessage("Message #" + i);
            System.out.println("Sending message #" + i);
            producer.send(message);
            Thread.sleep(DELAY);
        }

        // tell the subscribers we're done
        producer.send(session.createTextMessage("END"));

        producer.close();
        session.close();

    } catch (Exception e) {
        System.out.println("Caught exception!");
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                System.out.println("Could not close an open connection...");
            }
        }
    }
}

From source file:org.jboss.narayana.quickstart.spring.Launch.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(
            Launch.class.getPackage().getName());
    ExampleService service = context.getBean(ExampleService.class);

    if (args.length == 1) {
        RecoveryManagerService recoveryManagerService = context.getBean(RecoveryManagerService.class);
        if (args[0].equals("-f")) {
            System.out.println("Generate something to recovery ...");
            service.testRecovery();//w  w w. j av  a 2s . co m
        } else if (args[0].equals("-r")) {
            System.out.println("start the recovery manager");
            recoveryManagerService.start();

            System.out.println("recovery manager scan ...");
            while (DummyXAResource.getCommitRequests() == 0) {
                Thread.sleep(1000);
            }

            System.out.println("stop the recovery manager");
            recoveryManagerService.stop();
        } else if (args[0].equals("-c")) {
            service.checkRecord();
        }
    } else {
        service.testCommit();
        service.checkRecord();
    }

    service.shutdownDatabase();
    TxControl.disable(true);
    TransactionReaper.terminate(true);
}

From source file:example.composite.dest.Producer.java

public static void main(String[] args) {
    String url = BROKER_URL;
    if (args.length > 0) {
        url = args[0].trim();//from  www.java  2s  . c  o m
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url);
    Connection connection = null;

    try {

        connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session
                .createQueue("test-queue,test-queue-foo,test-queue-bar,topic://test-topic-foo");
        MessageProducer producer = session.createProducer(destination);

        for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
            TextMessage message = session.createTextMessage("Message #" + i);
            System.out.println("Sending message #" + i);
            producer.send(message);
            Thread.sleep(DELAY);
        }

        producer.close();
        session.close();

    } catch (Exception e) {
        System.out.println("Caught exception!");
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                System.out.println("Could not close an open connection...");
            }
        }
    }
}

From source file:com.taveloper.http.test.PwTest.java

/**
 * @param args the command line arguments
 *//*w  w w  .j a v  a 2 s.co  m*/
public static void main(String[] args) throws IOException, InterruptedException {
    ExecutorService es = Executors.newFixedThreadPool(1);
    // ?     
    try {
        for (int i = 0; i < a.length; i++) {
            String s1 = a[i];
            for (int j = 0; j < a.length; j++) {
                String s2 = a[j];
                Pw pw = new Pw(s1 + s2);
                es.submit(pw);
            }
        }
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    if (es.isShutdown()) {
    } else {
        Thread.sleep(1000);
    }
}

From source file:com.opengamma.bbg.replay.BloombergTicksCollectorLauncher.java

/**
 * Starts the Bloomberg Ticks Collector.
 * /*from  w  w  w.  ja  v a  2  s .c o m*/
 * @param args Not needed
 */
public static void main(String[] args) { // CSIGNORE

    int duration = 0;
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("d", "duration", true, "minutes to run");
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("duration")) {
            duration = Integer.parseInt(cmd.getOptionValue("duration"));
        }
    } catch (ParseException exp) {
        s_logger.error("Option parsing failed: {}", exp.getMessage());
        return;
    }

    BloombergTicksCollectorLauncher launcher = new BloombergTicksCollectorLauncher();
    launcher.run();
    if (duration > 0) {
        try {
            Thread.sleep(duration * 60 * 1000);
        } catch (InterruptedException e) {
        }
        launcher.exit();
    }
}

From source file:MyThread.java

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

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

    System.out.println("\nHere is output from list():");
    groupA.list();//from  w w w . j  a  v  a  2  s  .  c  o  m
    groupB.list();

    System.out.println("Suspending Group A");
    Thread tga[] = new Thread[groupA.activeCount()];
    groupA.enumerate(tga); // get threads in group
    for (int i = 0; i < tga.length; i++) {
        ((MyThread) tga[i]).suspendMe(); // suspend each thread
    }

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

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

    try {
        System.out.println("Waiting for threads to finish.");
        ob1.join();
        ob2.join();
        ob3.join();
        ob4.join();
    } catch (Exception e) {
        System.out.println("Exception in Main thread");
    }
    System.out.println("Main thread exiting.");
}