List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:Main.java
public static void main(String[] args) throws Exception { Robot r = new Robot(); r.mouseMove(35, 35);//from w w w. ja v a2s . co m r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); Thread.sleep(50); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { new Worker().start(); Thread.sleep(1000); new Worker().start(); Thread.sleep(1000);/* ww w . ja va2s . c om*/ new Worker().start(); Thread.sleep(1000); System.out.println("Barrier automatically resets."); new Worker().start(); Thread.sleep(1000); new Worker().start(); Thread.sleep(1000); new Worker().start(); }
From source file:Main.java
public static void main(String args[]) throws Throwable { InputStream in = Main.class.getResourceAsStream(args[0]); AudioStream as = new AudioStream(in); AudioPlayer.player.start(as);/*from w ww .j a va 2 s . c o m*/ Thread.sleep(5000); }
From source file:Main.java
public static void main(String... s) { cdl = new CountDownLatch(1); Thread a = new Thread(() -> { System.out.println("started a"); try {//from w ww. ja v a 2 s . c o m Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } cdl.countDown(); System.out.println("stoped a"); }); Thread b = new Thread(() -> { System.out.println("started b"); System.out.println("wait a"); try { cdl.await(); } catch (Exception e) { e.printStackTrace(); } System.out.println("stoped b"); }); b.start(); a.start(); }
From source file:Main.java
public static void main(String[] args) { try {// ww w . ja v a2 s . co m // create a new process System.out.println("Creating Process..."); Process p = Runtime.getRuntime().exec("notepad.exe"); // wait 10 seconds System.out.println("Waiting..."); Thread.sleep(10000); // kill the process p.destroy(); System.out.println("Process destroyed."); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); Future<?> future = executor.submit(() -> { try {//w ww . j av a2 s .co m Thread.sleep(1000); } catch (Exception e) { System.out.println("Epic fail."); } }); System.out.println("Waiting for task to finish.."); future.get(); System.out.println("Task finished!"); executor.shutdown(); }
From source file:CurrentThreadDemo.java
public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println("Current thread: " + t); t.setName("My Thread"); System.out.println("After name change: " + t); try {//from ww w. j a v a 2 s.co m for (int n = 5; n > 0; n--) { System.out.println(n); Thread.sleep(1000); } } catch (InterruptedException e) { System.out.println("Main thread interrupted"); } }
From source file:FlagComm.java
public static void main(String args[]) { FlagSend s = new FlagSend(); FlagRec r = new FlagRec(s); Thread st = new Thread(s); Thread rt = new Thread(r); rt.setDaemon(true);//from ww w. j a v a 2s . c o m st.start(); rt.start(); try { while (s.isValid) { Thread.sleep(100); } } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) { map = new WeakHashMap(); map.put("A", "B"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("A")) { try { Thread.sleep(1000); System.gc();// ww w .j a va2 s . co m } catch (InterruptedException ignored) { } System.out.println("Has A"); System.gc(); } } }; Thread t = new Thread(runner); t.start(); System.out.println("Main waiting"); try { t.join(); } catch (InterruptedException ignored) { } System.gc(); }
From source file:Main.java
public static void main(String args[]) throws Exception { // Create a test frame Frame frame = new Frame("Hello"); frame.add(new Label("Minimize demo")); frame.pack();//from w w w . j a v a 2s . com // Show the frame frame.setVisible(true); // Sleep for 5 seconds, then minimize Thread.sleep(5000); frame.setState(Frame.ICONIFIED); frame.setVisible(false); // Sleep for 5 seconds, then restore Thread.sleep(5000); frame.setState(Frame.NORMAL); frame.setVisible(true); // Sleep for 5 seconds, then kill window Thread.sleep(5000); frame.setVisible(false); frame.dispose(); // Terminate test System.exit(0); }