List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:InterfaceTest.java
public static void main(String args[]) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); engine.eval("function run() {print('www.java2s.com');}"); Invocable invokeEngine = (Invocable) engine; Runnable runner = invokeEngine.getInterface(Runnable.class); Thread t = new Thread(runner); t.start();// w ww . ja va 2 s .c o m t.join(); }
From source file:Main.java
public static void main(String[] args) { Thread t1 = new Thread(Main::print); t1.start();/* w ww .j a va 2 s . c o m*/ try { t1.join(); // "main" thread waits until t1 is terminated } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Done."); }
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 ww w . j a v a2 s . c o m System.gc(); } } }; Thread t = new Thread(runner); t.start(); try { t.join(); } catch (InterruptedException ignored) { } }
From source file:MyThread.java
public static void main(String args[]) { System.out.println("Main thread starting."); Thread thrd = new Thread(new MyThread()); thrd.start();//from ww w .ja v a 2 s. co m try { thrd.join(); } catch (InterruptedException exc) { System.out.println("Main thread interrupted."); } System.out.println("Main thread ending."); }
From source file:Main.java
public static void main(String args[]) throws Exception { Thread t = new Thread(new ThreadDemo()); t.start();/*ww w.j a va 2s . c om*/ // waits for this thread to die t.join(); System.out.print(t.getName()); // checks if this thread is alive System.out.println(", status = " + t.isAlive()); }
From source file:edu.gmu.isa681.server.Main.java
public static void main(String[] args) { log.info("Starting server..."); final Server server = new Server(Constants.SERVER_PORT); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { server.shutdown();/*from w ww. j a va 2 s.c o m*/ } }); Thread thread = new Thread(server, "ServerThread"); thread.start(); try { thread.join(); } catch (InterruptedException ex) { log.error(ex); } //TODO: implement some CLI to admin the server }
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) { }/* ww w. j a va2 s . c o 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: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();//from w w w . j a va 2s. 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:ThreadDemo.java
public static void main(String args[]) throws Exception { Thread t = new Thread(new ThreadDemo()); // this will call run() function t.start();//from w w w . j av a 2 s . c om // waits for this thread to die t.join(); // tests if this thread is alive System.out.println("status = " + t.isAlive()); }
From source file:Main.java
public static void main(String a[]) throws Exception { MyThread tt1 = new MyThread(50); MyThread tt2 = new MyThread(75); Thread t1 = new Thread(tt1, "Test thread 1"); Thread t2 = new Thread(tt2, "Test thread 2"); t1.start();// www . j a v a 2s . c o m t2.start(); t1.join(); t2.join(); }