Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is use of threads how many ways to create thread

Answer Posted / madhusudhan

use of thread:1.concurrent execution of thread.
2.Program security.
Thread can be create in 2 ways
1.using Thread class
2.using Runnable interface
Example:
//first way of creating thread
class Thread1 extends Thread
{
public void run()
{
for(int i=0;i<1000;i++)
{
System.out.println(hashcode()+":"+i);
}
}
}
//second way of creating thread
class Thread2 implements Runnable
{
public void run()
{
for(int i=1000;i<2000;i++)
{
System.out.println(hashcode()+":"+i);
}
}
}
public class M
{
public static void main(String args[])
{
Thread1 t1=new Thread1();
t1.start();
Thread2 t2=new Thread2();
Thread t=new Thread(t2);
t.start();
}
}

Is This Answer Correct ?    22 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?

8101


Can we declare the main method of our class as private?

991


What is boolean law?

1059


Can we declare a static variable inside a method?

993


How to display arraylist values in java?

1001


Which variables are stored in heap?

1023


What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?

974


Can a class be private or protected in java?

1056


Give some features of interface?

1065


What is oops in java?

1013


How are variables stored?

974


Can we define constructor in inner class?

997


Explain listiterator and methods in listiterator?

1010


Explain the JDB in depth & command line.

1012


What is this keyword used for?

1112