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

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//  ww w  .j  a va2  s.  c  o  m
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                System.out.println("Old tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                System.out.println("New tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    g.setColor(Color.yellow);
    int ovalSize = (size.width < size.height) ? size.width : size.height;
    ovalSize /= 2;
    g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize);

    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:BadThreads.java

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

    (new CorrectorThread()).start();
    message = "Mares do not eat oats.";
    Thread.sleep(2000);
    // Key statement 2:
    System.out.println(message);/*from   ww  w . ja v  a  2s  .c  om*/
}

From source file:org.wso2.carbon.tfl.realtime.TflStream.java

public static void main(String[] args) throws XMLStreamException {
    try {/* w  w w .  j  a  v  a  2s  . c o  m*/
        Update update = new Update(System.currentTimeMillis(), 1000, endPointBus);
        GetData busData = new GetData();
        busData.start();
        log.info("started collecting data");
        Thread.sleep(30000);
        update.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:test.node.TestUnboudedJobRunner.java

public static void main(String[] args) {
    // Test Job/*from   ww  w.ja  v  a 2 s  .c om*/
    TestUnboundedJob testJob = new TestUnboundedJob();

    try {

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Submit Job
        log.debug("Submitting Job");

        sw.start();

        GridJobFuture future = node.getJobSubmissionService().submitJob(testJob, new ResultCallback() {

            public void onResult(Serializable result) {
                System.err.println(result);
            }

        });

        while (!future.isJobFinished()) {
            Thread.sleep(1000);
        }

        sw.stop();
        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sm.test.TestClient.java

public static void main(String[] args) {
    ccf = ClusterClientFactory.connect(HOST_CONNECT_URL, STORENAME);
    client = ccf.getDefaultStore();/*w w w.java 2  s  .c om*/
    while (true) {
        try {
            long time = System.currentTimeMillis() / 1000;
            ByteArrayConverter converter = new ByteArrayConverter();
            Key<ByteArray> key = Key.createKey(new ByteArray("1.abcdef".getBytes()));
            Bar bar = new Bar();
            client.put(key, new ByteArray("FooBar".getBytes()));
            Value<ByteArray> value = client.get(key);
            System.out.println("" + new String(value.getData().get()));
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        if (false)
            break;
    }
    client.close();
    ccf.close();
}

From source file:org.opencredo.demos.twityourl.TwitYourl.java

public static void main(String[] args) throws IOException, TwitterException, InterruptedException {

    TwitterStreamConfiguration config = parseCommandLine(args);

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configFiles, TwitYourl.class);
    TwitterStreamInboundChannelAdapter twitterFeed = (TwitterStreamInboundChannelAdapter) context
            .getBean("twitterStreamFeed");
    twitterFeed.setTwitterStreamConfiguration(config);

    Thread.sleep(10000);
}

From source file:com.kixeye.chassis.bootstrap.AppMain.java

/**
 * Main entry method.//from   ww w .  j av a2 s .  c  om
 *
 * @param args the application arguments
 */
public static void main(String[] args) throws Exception {

    System.out.println("Starting application with arguments " + Arrays.toString(args));

    Arguments arguments = loadArguments(args);

    if (arguments == null) {
        return;
    }

    initializeLogging(arguments);

    application = new Application(arguments);

    registerShutdownHook();

    application.start();

    while (application.isRunning()) {
        //keep the main thread alive
        Thread.sleep(500);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch clock = new StopWatch();
    NumberFormat format = NumberFormat.getInstance();

    System.out.println("How long does it take to take the sin of 0.34 ten million times?");
    clock.start();//ww  w  .ja  va  2s. c  o  m
    for (int i = 0; i < 100000000; i++) {
        Math.sin(0.34);
    }
    clock.stop();

    System.out.println("It takes " + clock.getTime() + " milliseconds");

    System.out.println("How long does it take to multiply 2 doubles one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        double result = 3423.2234 * 23e-4;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("How long does it take to add 2 ints one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        int result = 293842923 + 33382922;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("Testing the split() method.");
    clock.reset();
    clock.start();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    clock.split();
    System.out.println("Split Time after 1 sec: " + clock.getTime());
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Split Time after 2 sec: " + clock.getTime());
    clock.unsplit();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Time after 3 sec: " + clock.getTime());

}

From source file:com.au.splashinc.JControl.MainCLI.java

public static void main(String[] args) throws AWTException, InterruptedException {
    MyControllers myControllers = new MyControllers();
    ArrayList<Controller> controllers = myControllers.GetControllers();
    myControllers = new MyControllers(true);
    ArrayList<Controller> controllers2 = myControllers.GetControllers();

    System.out.println("Let's do this");
    System.out.println("Length without all USB: " + controllers.size());
    System.out.println("Length with all USB: " + controllers2.size());
    AControllerLoader mjs = new DarkForcesJsonLoader("This is a test");
    mjs.LoadConfig();/* w  w  w. j a  v  a 2  s. c o m*/
    //JSONObject obj = new JSONObject();
    //obj.put("Hello", "World");
    //System.out.println("JSON String: " + obj.toJSONString());
    if (controllers.size() > 0) {
        try {
            MyController controller = new MyController(controllers.get(0));
            AControllerAction buttonAction = new SimpleControllerAction(controller, mjs);
            while (true) {
                buttonAction.Execute();
                Thread.sleep(20);
            }
        } catch (AWTException ex) {
            System.out.println(ex.toString());
        }
    }
}

From source file:MainClass.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");
    MainClass sac1 = new MainClass(url1);
    MainClass sac2 = new MainClass(url2);
    MainClass sac3 = new MainClass("1.au");
    sac1.play();/*from   w ww .ja v  a 2  s .  c  om*/
    sac2.loop();
    sac3.play();
    try { // Delay for loop
        Thread.sleep(2000);
    } catch (InterruptedException ie) {
    }
    sac2.stop();
}