List of usage examples for java.lang ThreadGroup ThreadGroup
public ThreadGroup(String name)
From source file:Main.java
public static void main(String[] args) { ThreadGroup group = new ThreadGroup("admin"); Thread t = new Thread(group, "website"); System.out.println("Threadgroup = " + group.getName()); String str = group.toString(); System.out.println(str);/*from w ww. j a v a 2 s . co m*/ }
From source file:ThreadGroupDemo1.java
public static void main(String[] args) { ThreadGroup tg = new ThreadGroup("My ThreadGroup"); MyThread mt = new MyThread(tg, "My Thread"); mt.start();//from w ww . j a va2 s .c om }
From source file:Main.java
public static void main(String[] args) { final ThreadGroup threadGroup = new ThreadGroup("workers"); ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(threadGroup, r); }/*from w ww. j ava 2 s .c om*/ }); System.out.println(threadGroup.activeCount()); }
From source file:ThreadDemo.java
public static void main(String[] args) { ThreadGroup tgrp = new ThreadGroup("Thread Group"); Thread t = new Thread(tgrp, new ThreadDemo()); t.start();//from ww w . jav a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { System.setProperty("java.security.policy", "file:/C:/java.policy"); SecurityManager sm = new Main(); System.setSecurityManager(sm); // check if accepting access for thread group is enabled sm.checkAccess(new ThreadGroup("example")); System.out.println("Allowed!"); }
From source file:MyThread.java
public static void main(String args[]) throws Exception { ThreadGroup group = new ThreadGroup("new Group"); MyThread t1 = new MyThread(group, "Thread1"); MyThread t2 = new MyThread(group, "Thread2"); t1.start();//from ww w . j ava 2 s . c o m t2.start(); Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); Thread th[] = new Thread[group.activeCount()]; group.enumerate(th); for (Thread t : th) { System.out.println(t.getName()); } Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); group.interrupt(); }
From source file:MyThread.java
public static void main(String args[]) throws Exception { ThreadGroup group = new ThreadGroup("Group"); ThreadGroup newGroup = new ThreadGroup(group, "new group"); MyThread t1 = new MyThread(group, "Thread1"); MyThread t2 = new MyThread(group, "Thread2"); t1.start();//from w ww .ja v a 2 s. com t2.start(); Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); Thread th[] = new Thread[group.activeCount()]; group.enumerate(th); for (Thread t : th) { System.out.println(t.getName()); } Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); group.interrupt(); }
From source file:MyThread.java
public static void main(String args[]) throws Exception { ThreadGroup tg = new ThreadGroup("My Group"); MyThread thrd = new MyThread(tg, "MyThread #1"); MyThread thrd2 = new MyThread(tg, "MyThread #2"); MyThread thrd3 = new MyThread(tg, "MyThread #3"); thrd.start();/*from ww w. j a v a2 s . c o m*/ thrd2.start(); thrd3.start(); Thread.sleep(1000); System.out.println(tg.activeCount() + " threads in thread group."); Thread thrds[] = new Thread[tg.activeCount()]; tg.enumerate(thrds); for (Thread t : thrds) System.out.println(t.getName()); thrd.myStop(); Thread.sleep(1000); System.out.println(tg.activeCount() + " threads in tg."); tg.interrupt(); }
From source file:NewThread.java
public static void main(String args[]) { ThreadGroup groupA = new ThreadGroup("Group A"); ThreadGroup groupB = new ThreadGroup("Group B"); NewThread ob1 = new NewThread("One", groupA); NewThread ob2 = new NewThread("Two", groupA); NewThread ob3 = new NewThread("Three", groupB); NewThread ob4 = new NewThread("Four", groupB); groupA.list();//from w ww . j ava 2 s. c o m groupB.list(); Thread tga[] = new Thread[groupA.activeCount()]; groupA.enumerate(tga); for (int i = 0; i < tga.length; i++) { ((NewThread) tga[i]).mysuspend(); } try { Thread.sleep(4000); } catch (InterruptedException e) { System.out.println("Main thread interrupted."); } System.out.println("Resuming Group A"); for (int i = 0; i < tga.length; i++) { ((NewThread) tga[i]).myresume(); } try { ob1.join(); ob2.join(); ob3.join(); ob4.join(); } catch (Exception e) { System.out.println("Exception in Main thread"); } }
From source file:MyThread.java
public static void main(String args[]) { ThreadGroup groupA = new ThreadGroup("Group A"); ThreadGroup groupB = new ThreadGroup("Group B"); MyThread ob1 = new MyThread("One", groupA); MyThread ob2 = new MyThread("Two", groupA); MyThread ob3 = new MyThread("Three", groupB); MyThread ob4 = new MyThread("Four", groupB); System.out.println("\nHere is output from list():"); groupA.list();// w w w. ja v a 2s. c om groupB.list(); System.out.println("Suspending Group A"); Thread tga[] = new Thread[groupA.activeCount()]; groupA.enumerate(tga); // get threads in group for (int i = 0; i < tga.length; i++) { ((MyThread) tga[i]).suspendMe(); // suspend each thread } try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Main thread interrupted."); } System.out.println("Resuming Group A"); for (int i = 0; i < tga.length; i++) { ((MyThread) tga[i]).resumeMe(); } try { System.out.println("Waiting for threads to finish."); ob1.join(); ob2.join(); ob3.join(); ob4.join(); } catch (Exception e) { System.out.println("Exception in Main thread"); } System.out.println("Main thread exiting."); }