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

public static void main(String[] argv) throws InterruptedException {
    //+//from   w  w w .j  a va  2s  . c om
    while (true) {
        System.out.println(new Date() + "\007");
        Thread.sleep(5 * 60 * 1000);
    }
    //-
}

From source file:de.zib.gndms.gndmc.test.gorfx.ESGFGet.java

public static void main(String[] args) throws Exception {

    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    InputStream is = new FileInputStream("/var/tmp/gndms/keystore/x509_proxy.pem");
    System.out.println(cf.generateCertificate(is));
    System.out.println(" ------------------------------------------------- ");
    Thread.sleep(1000);
    System.out.println("AND: " + cf.generateCertificate(is));
    System.exit(0);/*  w  ww.j  a  va2  s. c o m*/

    ESGFGet cnt = new ESGFGet();
    cnt.run(args);
    System.exit(0);

}

From source file:com.jmstoolkit.pipeline.Main.java

/**
 *
 * @param args/* w w w  . jav  a  2s.c  o  m*/
 */
public static void main(final String[] args) {
    try {
        Settings.loadSystemSettings("jndi.properties");
        Settings.loadSystemSettings("app.properties");
    } catch (JTKException ex) {
        System.out.println("Failed to load application settings");
        System.out.println(JTKException.formatException(ex));
        System.exit(1);
    }

    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
            "/infrastructure-context.xml", "/mdb-context.xml", "/jmx-context.xml", "/logging-context.xml" });
    applicationContext.start();

    final DefaultMessageListenerContainer dmlc = (DefaultMessageListenerContainer) applicationContext
            .getBean("listenerContainer");
    if (dmlc != null) {
        dmlc.start();
        final Pipeline pipeline = (Pipeline) applicationContext.getBean("pipelineService");
        // enable access to the original application context
        pipeline.setApplicationContext(applicationContext);

        // Insure that the Pipeline loads configuration files AFTER
        // the listenerContainer is running.
        while (!dmlc.isRunning()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
        }
        pipeline.loadPlugins();
        pipeline.sendProperties();
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
        }
    }
}

From source file:de.avanux.livetracker.sender.LocationSender.java

public static void main(String[] args) {
    try {// w  w w .jav  a 2  s.  c o m
        LocationSender sender = new LocationSender();
        Configuration configuration = sender.requestConfiguration(args[0]);
        float lon = 8.9842f;
        for (int i = 0; i < 10; i++) {
            sender.sendPositionData(configuration, 50.2911f, lon);
            //                lon += 0.002;
            lon += 0.005;
            log.debug("Waiting for " + configuration.getMinTimeInterval() + " seconds.");
            Thread.sleep(configuration.getMinTimeInterval() * 1000);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.couragelabs.logging.LogAppenderTestFixture.java

/**
 * Use this method to test the appender. Run this first, then run
 * GlobalContextSocketAppender::main/*from  www  .  j  a v a2 s  . co m*/
 *
 * @param args Program arguments. None are needed.
 * @throws java.lang.Exception if things go wrong
 */
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    ServerSocket serverSocket = new ServerSocket(PORT);

    System.out.println("Starting listen loop.");
    while (true) {
        try {
            final Socket clientSocket = serverSocket.accept();
            System.out.println("Received client connection.");
            new Thread() {
                @Override
                public void run() {
                    ObjectInputStream i = null;
                    try {
                        i = new ObjectInputStream(clientSocket.getInputStream());
                        while (true) {
                            Object received = i.readObject();
                            System.out.println(ToStringBuilder.reflectionToString(received,
                                    ToStringStyle.SHORT_PREFIX_STYLE));
                            Thread.sleep(1000);
                        }
                    } catch (EOFException e) {
                        System.out.println("Client closed connection.");
                    } catch (Throwable t) {
                        t.printStackTrace();
                    } finally {
                        if (i != null) {
                            try {
                                i.close();
                            } catch (Throwable t) {
                                t.printStackTrace();
                            }
                        }
                    }
                }
            }.start();
            Thread.sleep(1000);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        System.out.println("Next...");
    }

}

From source file:com.anton.dev.tqrbs2.basic.BasicJava.java

public static void main(String[] args) throws Exception {
    ConnectionFactory cf = new CachingConnectionFactory();

    // set up the queue, exchange, binding on the broker
    RabbitAdmin admin = new RabbitAdmin(cf);
    Queue queue = new Queue("myQueue");
    admin.declareQueue(queue);/*from w w w .j  a va  2 s . co  m*/
    TopicExchange exchange = new TopicExchange("myExchange2");
    admin.declareExchange(exchange);
    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*"));

    // set up the listener and container
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
    Object listener = new Object() {
        public void handleMessage(String foo) {
            LOGGER.info("Recibiendo Java: " + foo);
        }
    };
    MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
    container.setMessageListener(adapter);
    container.setQueueNames("myQueue");
    container.start();

    // send something
    RabbitTemplate template = new RabbitTemplate(cf);
    String msg = "Hello, world Rabbit!";
    LOGGER.info("Enviando Java: " + msg);
    template.convertAndSend("myExchange2", "foo.bar", msg);
    Thread.sleep(1000);
    container.stop();
}

From source file:com.l2jfree.gameserver.util.ModuleTester.java

public static void main(String[] args) throws Exception {
    Config.load();/*from w  ww .j  a va 2  s  .c  o m*/
    Config.DATAPACK_ROOT = new File("../l2jfree-datapack");
    //L2DatabaseFactory.getInstance();

    // here comes what you want to test
    //SkillTable.getInstance();
    //HtmCache.getInstance();

    //new WeaponSQLConverter().convert();
    //convertSkills();

    System.gc();
    System.runFinalization();
    Thread.sleep(1000);
}

From source file:org.another.logserver.Starter.java

/**
 *
 * @param args//  w w w.  jav  a2  s .  c  om
 */
public static void main(String[] args) {

    LOGGER.info("Starting Another Log server ...");

    // Initialize components

    LOGGER.debug("Starting Spring context ...");
    final ApplicationContext springContext = new ClassPathXmlApplicationContext("spring.xml");

    LOGGER.info("Spring intilization: {}", springContext.getStartupDate());

    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            super.run();
            LOGGER.debug("Running Shutdown Hook");

            Configurator conf = springContext.getBean("configurator", Configurator.class);
            for (IEndPoint ep : conf.getConfiguredEndPoints().values()) {
                ep.stop();
            }

        }

    });

    ((AbstractApplicationContext) springContext).registerShutdownHook();

    LOGGER.debug("Entering wait loop");
    try {
        while (true) {
            Thread.sleep(1000 * 60 * 60);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }

}

From source file:Snippet151.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL);
    table.addListener(SWT.SetData, new Listener() {
        public void handleEvent(Event e) {
            TableItem item = (TableItem) e.item;
            int index = table.indexOf(item);
            item.setText("Item " + data[index]);
        }/*ww w .j a  v a2s .c  o m*/
    });
    Thread thread = new Thread() {
        public void run() {
            int count = 0;
            Random random = new Random();
            while (count++ < 500) {
                if (table.isDisposed())
                    return;
                // add 10 random numbers to array and sort
                int grow = 10;
                int[] newData = new int[data.length + grow];
                System.arraycopy(data, 0, newData, 0, data.length);
                int index = data.length;
                data = newData;
                for (int j = 0; j < grow; j++) {
                    data[index++] = random.nextInt();
                }
                Arrays.sort(data);
                display.syncExec(new Runnable() {
                    public void run() {
                        if (table.isDisposed())
                            return;
                        table.setItemCount(data.length);
                        table.clearAll();
                    }
                });
                try {
                    Thread.sleep(500);
                } catch (Throwable t) {
                }
            }
        }
    };
    thread.start();
    shell.open();
    while (!shell.isDisposed() || thread.isAlive()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.fusesource.examples.activemq.SimplePublisher.java

public static void main(String args[]) {
    Connection connection = null;

    try {//from  w ww.j  a  v  a 2 s.  co  m
        // JNDI lookup of JMS Connection Factory and JMS Destination
        Context context = new InitialContext();
        ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME);

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

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(DESTINATION_NAME);

        MessageProducer producer = session.createProducer(topic);

        producer.setTimeToLive(MESSAGE_TIME_TO_LIVE_MILLISECONDS);

        for (int i = 1; i <= NUM_MESSAGES_TO_BE_SENT; i++) {
            TextMessage message = session.createTextMessage(i + ". message sent");
            LOG.info("Sending to destination: " + DESTINATION_NAME + " this text: '" + message.getText());
            producer.send(message);
            Thread.sleep(MESSAGE_DELAY_MILLISECONDS);
        }

        // Cleanup
        producer.close();
        session.close();
    } catch (Throwable t) {
        LOG.error(t);
    } finally {
        // Cleanup code
        // In general, you should always close producers, consumers,
        // sessions, and connections in reverse order of creation.
        // For this simple example, a JMS connection.close will
        // clean up all other resources.
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                LOG.error(e);
            }
        }
    }
}