3:37 pm - Tuesday September 21, 2573

Thread Example program for destroy()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and the use of void destroy()
*/
class Suspend implements Runnable
{

    public void run()
	{
	        try
		{
            Thread.sleep(10);
        }
		catch (Exception e)
		{
            System.out.println(e);
        }
        for (int i = 0; i <= 1; i++)
		{
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }
	}
class Y
{
    public static void main(String args[]) throws Exception
	{
        Thread th = new Thread(new Suspend());
        Thread th1 = new Thread(new Suspend());
        System.out.println("Starting " + th.getName() + "...");
        th.start();
        System.out.println("Suspending " + th.getName() + "...");
        //Suspend the thread.
        th.suspend();
        th1.start();
        th1.join();
        // Resume the thread.
        th.resume();
    }
}

output

Strating Thread 0
Suspending Thread 1
Thread 1 0
Thread 1 1
Thread 0 0
Thread 0 1

Filed in: Z-A All Java Codes

Comments are closed.