what is use of threads how many ways to create thread
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / subash chandra bose l
there are many uses of threads and the main use is to
execute several process at once.
there are two ways of creating a thread and
1. extending a Thread class
2. implementing Runnable interface
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / poorna chandar rao.yerrabothu
thread is light whight processes its take low memory and low
proceesing time
there are two types thereds creatd
extending the thered class
implementing the runnable interface
| Is This Answer Correct ? | 4 Yes | 2 No |
what is meant by HQL?
What is style and indentation?
what is the use of private constructor in core java?
3 Answers OnMobile, Satyam, Yash Technologies,
Is a boolean 1 bit?
When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?
steps to connect with Oracle Databse using TYPE-2 Jdbc driver.
why pointer is not used in java?
How can we find the actual size of an object on the heap?
What is object in java?
How will you load a specific locale?
What is the difference between stringbuffer and stringbuilder class?
How do you declare a variable?