[JAVA100 cases] 063, thread group

  / ** 
  * <p> Title: thread groups </ p> 
  * <p> Description: The thread management group following a number of threads.    </ P> 
  * <p> Copyright: Copyright (c) 2003 </ p> 
  * <p> Filename: myThreadgroup.java </ p> 
  * @ Version 1.0 
  * / 
  Public class myThreadgroup extends Thread ( 
  Public static int flag = 1; 
  ThreadGroup tgA; 
  ThreadGroup tgB; 
  / ** 
  * <br> Description: Lord method 
  * <br> Input parameters: 
  * <br> Return type: 
  * / 
  Public static void main (String [] args) ( 
  MyThreadgroup dt = new myThreadgroup (); 
  / / A group statement threads 
  Dt.tgA = new ThreadGroup ( "A"); 
  / / Statement Thread Group B 
  Dt.tgB = new ThreadGroup ( "B"); 
  For (int i = 1; i <3; i + +) 
  New thread1 (dt.tgA, i * 1000, "one" + i); 
  For (int i = 1; i <3; i + +) 
  New thread1 (dt.tgB, 1000, "two" + i); 
  / / Start this thread and all threads Group dt.start (); 
  ) 
  / ** 
  * <br> Description: run coverage, thread control group 
  * <br> Input parameters: 
  * <br> Return type: 
  * / 
  Public void run () ( 
  Try ( 
  This.sleep (5000); 
  This.tgB.checkAccess (); 
  / / Stop threads Group B, 
  This.tgB.stop (); 
  System.out.println ("************** tgB stop !***********************"); 
  This.sleep (1000); 
  / / A group checks whether the thread can change this.tgA.checkAccess (); 
  / / Stop threads Group A 
  This.tgA.stop (); 
  System.out.println ("************** tgA stop !***********************"); 

  ) Catch (SecurityException es) ( 
  System.out.println ("**"+ es); 
  ) Catch (Exception e) ( 
  System.out.println ("::"+ e); 
  ) 
  ) 
  ) 
  / ** 
  * <p> Title: Thread of </ p> 
  * <p> Description: The constructor of the parameters for different threads </ p> 
  * <p> Copyright: Copyright (c) 2003 </ p> 
  * <p> Filename: thread1.java </ p> 
  * @ Author DU 
  * @ Version 1.0 
  * / 
  (Class thread1 extends Thread 
  Int pauseTime; 
  String name; 
  Public thread1 (ThreadGroup g, int x, String n) ( 
  Super (g, n); 
  PauseTime = x; 
  Name = n; 
  Start (); 
  ) 
  / ** 
  * <br> Methodology: to be covered by the method. 
  * <br> Input parameters: 
  * <br> Return type: 
  * / 
  Public void run () 
  ( 
  While (true) ( 
  Try ( 
  System.out.print (name +"::::"); 
  This.getThreadGroup (). List ();// access thread group information Thread.sleep (pauseTime); 
  ) Catch (Exception e) ( 
  System.out.println (e); 
  ) 
  ) 
  ) 
  ) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply