wellnwill Marathahalli Bangalore

Thread Continue

class MyTable extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
 }
}
}

class Test
{
 public static void main(String args[])
 {
  MyTable mt1=new MyTable();
  mt1.start();
  for(int i=1;i<5;i++)
 {
  System.out.println(i*10);
 }
 }
}


class MyTable extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
 }
}
}
class Test
{
 public static void main(String args[])
 {
  MyTable mt1=new MyTable();
  mt1.start();
  Thread.currentThread().setPriority(1);
  for(int i=1;i<5;i++)
 {
  System.out.println(i*10);
 }
 }
}


join()

if first thread wants to wait until completion of second thread task then first thread can call join() method. public final voud join() public final voud join(long miliseconds)

class MyTable11 extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
}
}
}

class Test
{
 public static void main(String args[])
 {
  MyTable mt1=new MyTable();
  mt1.start();
  try{
  mt1.join();
  }
  catch(Exception e)
  {}
  for(int i=1;i<5;i++)
 {
  System.out.println(i*10);
 }
 }
}
//O/P-1st mt1 start() will be executed then main().


class MyTable11 extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
 }
}
}

class Test
{
 public static void main(String args[])
 {
  MyTable mt1=new MyTable();
  mt1.start();
  try{
  mt1.join(1);
  }
  catch(Exception e)
  {
	  
  }
  for(int i=1;i<5;i++)
 {
  System.out.println(i*10);
 }
 }
}

Public void interrupt()

if we call sleep() or wait() on thread then thread go to sleep or wait state. Calling interrupt() on sleeping or waiting thread, will interrupt the thread and will throw interruptedException.

class MyTable11 extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
  
  try
  {
  Thread.sleep(1000);
  }
  catch(InterruptedException e)
  {
	  System.out.println(e);
  }}}}
class Test
{
 public static void main(String args[])
 {
  MyTable11 mt1=new MyTable11();
  mt1.start();
for(int i=1;i<5;i++)
 {
  System.out.println(i*10);
   }
}
}


class MyTable11 extends Thread
{
public void run()
{
 for(int i=1;i<5;i++)
 {
  System.out.println(i*11);
  
  try
  {
  Thread.sleep(1000);
  }
  catch(InterruptedException e)
  {
	  System.out.println(e);
  }
 }
}
}
class Test1
{
 public static void main(String args[])
 {
  MyTable11 mt1=new MyTable11();
  mt1.start();
  mt1.interrupt();
 }
}


Footer with Map

Top