/**
* <p>title: Thread control </p>
* <p>description: Controls on threads, interrupts, hangs, restores, stops </p>
* <p>copyright:copyright (c) 2003</p>
* <P>FILENAME:THREADCTRL.JAVA</P>
* @version 1.0< br> */
public class threadctrl{
public static void Main (String [] main) {
New Threadctrl ()
/**
*<br> Method Description: constructor, control other threads
*<br> input parameters:
*<br> return type:
*/
Threadctrl () {
try{< br> Thread TM = Thread.CurrentThread ();
Threadchild td = New Threadchild ();
Td.start ();
Tm.sleep (500);
System.out.println ("Interrupt Child thread");
Td.interrupt ();
System.out.println ("Let Child Thread wait!");
//td.wait ();
//td.suspend ();
Tm.sleep (1000);
System.out.println ("Let Child thread Working");
Td.fauxresume ();
//td.resume ();
Tm.sleep (1000);
Td.runflag = false;
System.out.println ("main over .... ..."), and;
}catch (Interruptedexception IE) {
System.out.println ("Inter main::" +ie);
} catch (Exception e) {
System.out.println ("Main::" +e);
}
}
}
/**
*<br> class Description: Controlled Thread class
*/
Class Threadchild extends Thread {
Boolean runflag = True
Boolean suspended = true;
Threadchild () {
}
Public synchronized void Fauxresume () {
suspended = false;
Notify ();
}
public void Run () {
while (runflag) {
System.out.println ("I am working ...");
try{
Sleep (1000);
}catch (interruptedexception e) {
System.out.println ("Sleep::" +e);
}
Synchronized (this) {
try{
if (suspended)
Wait ();
}catch (interruptedexception e) {
System.out.println ("Wait::" +e);
}
}
}
System.out.println ("Thread over ...");
}
}