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

public static void main(String[] args) {
    System.out.println(/*from  w  w w . j ava  2s  .  co  m*/
            "in main() - Thread.currentThread().getPriority()=" + Thread.currentThread().getPriority());

    System.out.println("in main() - Thread.currentThread().getName()=" + Thread.currentThread().getName());

    Thread threadA = new Thread(makeRunnable(), "threadA");
    threadA.start();

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

    System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority());
}

From source file:Test.java

public static void main(String[] args) {
    final AtomicLong orderIdGenerator = new AtomicLong(0);
    final List<Item> orders = Collections.synchronizedList(new ArrayList<Item>());

    for (int i = 0; i < 10; i++) {
        Thread orderCreationThread = new Thread(new Runnable() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    long orderId = orderIdGenerator.incrementAndGet();
                    Item order = new Item(Thread.currentThread().getName(), orderId);
                    orders.add(order);//  www  .  j  ava 2  s  .  c om
                }
            }
        });
        orderCreationThread.setName("Order Creation Thread " + i);
        orderCreationThread.start();
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Set<Long> orderIds = new HashSet<Long>();
    for (Item order : orders) {
        orderIds.add(order.getID());
        System.out.println("Order id:" + order.getID());
    }
}

From source file:ProducerComsumer.java

public static void main(String[] args) {
    final ProducerComsumer ch = new ProducerComsumer();

    Runnable runA = new Runnable() {
        public void run() {
            try {
                String str;//from   w w w. jav a  2s  .co  m
                Thread.sleep(500);

                str = "multithreaded";
                ch.putIn(str);
                str = "programming";
                ch.putIn(str);

                str = "with Java";
                ch.putIn(str);
            } catch (InterruptedException x) {
                x.printStackTrace();
            }
        }
    };

    Runnable runB = new Runnable() {
        public void run() {
            try {
                Object obj;

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");

                Thread.sleep(500);

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");
            } catch (InterruptedException x) {
                x.printStackTrace();
            }
        }
    };

    Thread threadA = new Thread(runA, "threadA");
    threadA.start();

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

From source file:com.jbrisbin.vpc.jobsched.JobScheduler.java

public static void main(String[] args) {
    ApplicationContext appCtx = new ClassPathXmlApplicationContext("/jobsched.xml");
    while (true) {
        try {/*from  w ww  .  j a v  a 2s . c om*/
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.platform.camel.app.SpringMain.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext springContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/move-file-context.xml");

    springContext.start();//w  w w. j av a2  s. co m
    Thread.sleep(100000);
    springContext.stop();
}

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

public static void main(String[] args) throws Exception {
    AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("basic-context.xml");
    RabbitTemplate template = ctx.getBean(RabbitTemplate.class);
    String msg = "Hello, world Rabbit!";
    LOGGER.info("Enviando Spring: " + msg);
    template.convertAndSend(msg);/*from www .  j  a  va 2 s.  co  m*/
    Thread.sleep(1000);
    ctx.destroy();
}

From source file:edu.eci.arsw.loannetsim.LoanNetworkSimulation.java

public static void main(String args[]) throws InterruptedException, IOException {
    ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

    int balancesSum = 0;

    List<Lender> lenders = setupLoanNetwork(NUMOF_LENDERS, ac);

    if (lenders != null) {
        for (Lender im : lenders) {
            new Thread(im).start();
        }//from   ww w. j a v a2 s . co  m
    }

    while (true) {
        Thread.sleep(10000);

        FixedMoneyLender.pause();

        System.out.println("*** PRESS ENTER TO VIEW STATISTICS ***");

        System.in.read();

        balancesSum = 0;
        for (Lender ln : lenders) {
            balancesSum += ln.getBalance();
        }

        System.out.println("Sum of balances:" + balancesSum);

        System.out.println("Press enter to continue simulation or Ctrl+C to abort...");

        System.in.read();

        FixedMoneyLender.resume();
        synchronized (lenders) {
            lenders.notifyAll();
        }

    }

}

From source file:org.apache.cxf.transport.xmpp.iq.Server.java

public static void main(String[] args) throws Exception {
    new ClassPathXmlApplicationContext("server-iq-applicationContext.xml");
    Thread.sleep(30 * 60 * 1000);
}

From source file:org.apache.cxf.transport.xmpp.pep.Server.java

public static void main(String[] args) throws Exception {
    new ClassPathXmlApplicationContext("server-pep-applicationContext.xml");
    Thread.sleep(30 * 60 * 1000);
}

From source file:org.apache.cxf.transport.xmpp.chat.Server.java

public static void main(String[] args) throws Exception {
    new ClassPathXmlApplicationContext("server-chat-applicationContext.xml");
    Thread.sleep(30 * 60 * 1000);
}