Multithreading Interview Questions in Java for Freshers What are the benefits of using Multithreading? 2


What are the two ways of implementing thread in Java?



Yüklə 0,82 Mb.
Pdf görüntüsü
səhifə4/20
tarix13.12.2023
ölçüsü0,82 Mb.
#176388
1   2   3   4   5   6   7   8   9   ...   20
Threads

3. What are the two ways of implementing thread in Java?
There are basically two ways of implementing thread in java as given below: 
Implementing Runnable interface in Java
Example:
Page 5
© Copyright by Interviewbit


Multithreading Interview Questions
class 
MultithreadingDemo
extends 
Thread
{
public void 
run
()
{
System.out.println(
"My thread is in running state."
);
}
public static void 
main
(String args[])
{
MultithreadingDemoobj=new MultithreadingDemo();
obj.start();
}

Output:
My thread is in running state.
Extending the Thread class.
Example:
class 
MultithreadingDemo
implements 
Runnable
{
public void 
run
()
{
System.out.println(
"My thread is in running state."
);
}
public static void 
main
(String args[])
{
MultithreadingDemo obj=new MultithreadingDemo();
Threadtobj =new Thread(obj); tobj.start();
}

Output: 
My thread is in running state. 
4. What's the difference between thread and process?
Page 6
© Copyright by Interviewbit


Multithreading Interview Questions
Thread: It simply refers to the smallest units of the particular process. It has the
ability to execute different parts (referred to as thread) of the program at the same
time.
Process: It simply refers to a program that is in execution i.e., an active program. A
process can be handled using PCB (Process Control Block). 

Yüklə 0,82 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   20




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin