what is a thread?

Answer Posted / venod.r.g

Thread is a class which extends Thread class or Implements
Runnable Interface.
Thread can run as an Independant process than current
Excecution steps. The Main thread that runs always is known
as CurrentThread accessed by Thread.currentThread();
Only one thread can access CPU time ( JVM then CPU). Multi
thread mechanisum is possible by making several threads in
waiting state and running only one at a time.

JVM assign priorities for every threads and accesses in a
Time Slicing / scheduled way considering the OS.

Defauls is normal.

Every object is like a Football to threads. hence Every
object must have methods to handle a thread. All the
players may be running in the field but only one player can
handle the Ball at a time. Object have methods like wait(),
notify() notifyAll() etc to catch and release the working
thread.

If you do not want a ball to change shape once it is
accessed by a thread then you need to synchronise the
statements or methods. Once synchronized the thread which
is the owner of the Object can only change the state of the
object.
//Method
public void synchronized x(){
}

//statement
synchronized (x);

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you convert bytes to string?

570


Can we override tostring method in java?

535


Explain with example the concept of constant variable in java.

642


What is JVM and is it platform independent?

565


What is a private class in java?

514






What is length in java?

574


Is an array a vector?

558


Can we use switch statement with strings?

627


How to compare strings in java?

508


What is the purpose of the main method?

547


What is internal iteration in java se 8?

633


What are constants and how to create constants in java?

560


How do you differentiate abstract class from interface?

533


How many bytes is a url?

568


hr interview how many minutes asking question

1573