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

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//from  w w  w .ja v a2  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) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    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);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

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

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

From source file:sample.TickTock.java

public static void main(String[] args) throws InterruptedException {
    LocalAppDeployer deployer = new LocalAppDeployer(new LocalDeployerProperties());
    String logId = deployer.deploy(createAppDeploymentRequest("log-sink-kafka", "ticktock"));
    String timeId = deployer.deploy(createAppDeploymentRequest("time-source-kafka", "ticktock"));
    for (int i = 0; i < 12; i++) {
        Thread.sleep(5 * 1000);
        System.out.println("time: " + deployer.status(timeId));
        System.out.println("log:  " + deployer.status(logId));
    }/*from  w  w w .  j  a v a 2  s  . c  o  m*/
    deployer.undeploy(timeId);
    deployer.undeploy(logId);
    System.out.println("time after undeploy: " + deployer.status(timeId));
    System.out.println("log after undeploy:  " + deployer.status(logId));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*from www .j  a  va 2  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) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    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);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

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

    tray.removePropertyChangeListener("trayIcons", pcl);

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

From source file:com.devti.JavaXMPPBot.FakeDaemonContext.java

public static void main(String[] args) {
    JavaXMPPBot daemon = new JavaXMPPBot();
    try {/* w  w w. j  a va2s.c o  m*/
        daemon.init(new FakeDaemonContext(args));
        daemon.start();
        while (Thread.activeCount() > 1) {
            Thread.sleep(1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
        //System.err.println("Can't load a bot: " + e.getLocalizedMessage());
        System.exit(1);
    }
}

From source file:org.openmrs.ModuleStory.java

public static void main(String args[]) throws IOException, InterruptedException {
    if (!skipDatabaseSetupPage()) {
        String databaseUserName = System.getProperty("database_user_name", "root");
        String databaseRootPassword = System.getProperty("database_root_password", "password");
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("curl http://localhost:8080/openmrs/auto_run_openmrs?local=en&remember=true"
                + "&database_user_name=" + databaseUserName + "&database_root_password="
                + databaseRootPassword);
        log.debug("Waiting 10 minutes for OpenMRS installation to complete!!");
        Thread.sleep(1000 * 60 * 10); //Waiting 10 minutes for installation to complete
    }/*  w  w  w .ja  v  a  2s  .co m*/
}

From source file:mini_mirc_client.Mini_mirc_client.java

public static void main(String[] args) {

    try {/*from ww  w  .j a v  a2s.co  m*/
        TTransport transport;
        transport = new TSocket("localhost", 2121);

        TProtocol protocol = new TBinaryProtocol(transport);
        miniIRC.Client client = new miniIRC.Client(protocol);

        Runnable updateThread;
        updateThread = new Runnable() {
            public void run() {
                try {
                    while (update) {
                        Thread.sleep(3000);

                        synchronized (transport) {
                            transport.open();
                            updateMsg(client);
                            transport.close();
                        }

                    }
                } catch (Exception E) {
                    E.printStackTrace();
                }
            }
        };

        new Thread(updateThread).start();

        perform(transport, client);

    } catch (Exception E) {
        E.printStackTrace();
    }
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 142");
    final Button button = new Button(shell, SWT.NONE);
    button.setSize(100, 100);//  www  .  java 2  s . c  om
    button.setText("Click");
    shell.pack();
    shell.open();
    button.addListener(SWT.MouseDown,
            e -> System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")"));
    final Point pt = display.map(shell, null, 50, 50);
    new Thread() {
        Event event;

        @Override
        public void run() {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event = new Event();
            event.type = SWT.MouseMove;
            event.x = pt.x;
            event.y = pt.y;
            display.post(event);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event.type = SWT.MouseDown;
            event.button = 1;
            display.post(event);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event.type = SWT.MouseUp;
            display.post(event);
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//from  w w  w .  j  a v  a  2 s .c  om
    }
    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) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

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

    Dimension size = tray.getTrayIconSize();

    TrayIcon[] icons = tray.getTrayIcons();

    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);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

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

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

From source file:zz.pseas.ghost.login.taobao.LogInTaobao.java

@SuppressWarnings("unused")
public static void main(String[] args) throws Exception {

    String tbuserNmae = "TBname";
    String tbpassWord = "TBpasssword";

    String url = "https://login.taobao.com/member/login.jhtml";
    WebDriver ie = BrowserFactory.getIE();
    ie.get(url);/*w w  w.  ja va 2s .  c o m*/

    Thread.sleep(5000L);

    Set<Cookie> cookies = ie.manage().getCookies();
    CookieStore store = DownloadUtil.convertToCookieStore(cookies);

    GhostClient client = new GhostClient("utf-8", store);

    String html = ie.getPageSource();
    String pbk = Jsoup.parse(html).select("input#J_PBK").attr("value");
    String pwd1 = RsaUtil.enCode(pbk, "10001", tbuserNmae);

    HashMap<String, String> map = new HashMap<String, String>();
    map.put("TPL_username", tbuserNmae);
    map.put("TPL_password", tbpassWord);
    map.put("fc", "default");
    map.put("from", "tb");
    map.put("gvfdcname", "10");
    map.put("keyLogin", "false");
    map.put("loginASR", "1");
    map.put("loginASRSuc", "1");
    map.put("loginType", "3");
    map.put("loginsite", "0");
    map.put("naviVer", "firefox|47");

    String ncoToken = Jsoup.parse(html).select("input#J_NcoToken").attr("value");
    map.put("ncoToken", ncoToken);

    map.put("newMini", "false");
    map.put("newMini2", "false");
    map.put("newlogin", "0");
    map.put("osVer", "windows|6.1");
    map.put("oslanguage", "zh-cn");
    map.put("qrLogin", "true");
    map.put("slideCodeShow", "false");
    map.put("sr", "1920*1080");

    String ua = Jsoup.parse(html).select("input#UA_InputId").attr("value");
    //map.put("ua", ua);

    String umToken = Jsoup.parse(html).select("input[name=um_token]").attr("value");
    map.put("um_token", umToken); // TODO get um_token

    String ans = client.post("https://login.taobao.com/member/login.jhtml", map);
    System.out.println(ans);
}

From source file:io.djigger.monitoring.java.instrumentation.subscription.HttpClientTracerTest.java

public static void main(String[] args) throws Exception {
    HttpClientTracerTest test = new HttpClientTracerTest();
    while (true) {
        test.call();/*from  w  ww  . j a v a2s.  co m*/
        Thread.sleep(3000);
    }
}