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 InterruptedException {
    Date date = new Date();
    Thread.sleep(1);
    Date other = new Date();
    out.printf("equals? = %s, hashCode? = %s %n", (date.equals(other)), (date.hashCode() == other.hashCode()));

    Date todayeOne = trim(date);//from w  ww.  ja  va  2  s.  c om
    Date todayTwo = trim(other);

    out.printf("equals? = %s, hashCode? = %s %n", (todayeOne.equals(todayTwo)),
            (todayeOne.hashCode() == todayTwo.hashCode()));

}

From source file:SimpleSplashScreen.java

public static void main(String[] arg) {
    JWindow jwin = new JWindow();
    jwin.getContentPane().add(new JLabel("Loading ZIP/JAR Manager...", SwingConstants.CENTER));
    jwin.setBounds(200, 200, 200, 100);/*ww  w  .jav a2 s . c o m*/
    jwin.setVisible(true);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    jwin.setVisible(false);
    jwin.dispose();

}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    JFrame frame = new JFrame();
    frame.add(new JLabel("Minimize demo"));
    frame.pack();//from   www .j a va2  s  .co  m

    // Show the frame
    frame.setVisible(true);

    // Sleep for 5 seconds, then minimize
    Thread.sleep(5000);
    frame.setState(Frame.ICONIFIED);

    // Sleep for 5 seconds, then restore
    Thread.sleep(5000);
    frame.setState(Frame.NORMAL);

    // Sleep for 5 seconds, then kill window
    Thread.sleep(5000);
    frame.setVisible(false);
    frame.dispose();

    // Terminate test
    System.exit(0);
}

From source file:Weak.java

public static void main(String args[]) {
    final Map map = new WeakHashMap();
    map.put(new String("Java2s"), "www.java2s.com");
    Runnable runner = new Runnable() {
        public void run() {
            while (map.containsKey("Java2s")) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ignored) {
                }/*from   w  w w .  ja va2 s  .co  m*/
                System.out.println("Waiting");
                System.gc();
            }
        }
    };
    Thread t = new Thread(runner);
    t.start();
    System.out.println("Main waiting");
    try {
        t.join();
    } catch (InterruptedException ignored) {
    }
}

From source file:Main.java

public static void main(String args[]) {
    final Map<String, String> map = new WeakHashMap<String, String>();
    map.put(new String("A"), "B");
    Runnable runner = new Runnable() {
        public void run() {
            while (map.containsKey("A")) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ignored) {
                }/*from   w ww.jav a 2 s .co m*/
                System.gc();
            }
        }
    };

    Thread t = new Thread(runner);
    t.start();
    try {
        t.join();
    } catch (InterruptedException ignored) {
    }
}

From source file:WaitComm.java

public static void main(String args[]) {
    WFlagSend s = new WFlagSend();
    WFlagRec r = new WFlagRec(s);
    Thread st = new Thread(s);
    Thread rt = new Thread(r);
    rt.setDaemon(true);//from   w w  w .j av a  2s.  c o  m
    st.start();
    rt.start();
    try {
        st.join();
        while (s.isValid) {
            Thread.sleep(100);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Play.java

public static void main(String args[]) {
    try {//from   w w  w. j a  va 2  s  .com
        // Loop
        URL url = new URL("http://java.sun.com/applets/other/Hangman/audio/whoopy.au");
        AudioClip clip = Applet.newAudioClip(url);
        clip.loop();
        Thread.sleep(5000);
        //Play
        File file = new File("bark.wav");
        clip = Applet.newAudioClip(file.toURL());
        clip.play();
        Thread.sleep(500);
        System.exit(0);
    } catch (InterruptedException e) {
    } catch (MalformedURLException e) {
    }
}

From source file:Main.java

public static void main(String args[]) {
    JWindow window = new JWindow();
    window.getContentPane().add(new JLabel("Loading", SwingConstants.CENTER));
    window.setBounds(500, 150, 300, 200);
    window.setVisible(true);/*from   www .  jav  a2  s. co m*/
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
    window.setVisible(false);
    JFrame frame = new JFrame();
    frame.add(new JLabel("Welcome Swing application..."));
    frame.setVisible(true);
    frame.setSize(300, 200);
    window.dispose();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ServerSocket server = new ServerSocket(8123);
    while (true) {
        Socket sock = server.accept();
        InetAddress addr = sock.getInetAddress();
        System.out.println("Connection made to " + addr.getHostName() + " (" + addr.getHostAddress() + ")");
        Thread.sleep(5000);
        sock.close();//from  ww w. j a  v a 2 s  . c o m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Runnable myRunnable = new Runnable() {
        @Override//from  ww  w.j a v  a  2s. com
        public void run() {
            try {
                System.out.println("Start: " + Thread.currentThread().getName());
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    };
    Thread one = new Thread(myRunnable);
    Thread two = new Thread(myRunnable);
    one.start();
    two.start();

    List<Thread> threads = getThreadsFor(myRunnable);
    for (Thread thread : threads)
        System.out.println("Found: " + thread.getName());
}