Moht
Moht
3. Thread Scheduling?
Thread scheduling in Java refers to the
process by which the Java Virtual
Machine (JVM) manages the execution
of multiple threads in a Java program.
The JVM uses various scheduling
algorithms to determine the order in
which threads get access to the CPU
for execution. The Thread class in Java
provides methods to set thread priority,
which can influence the scheduling
behavior, although the actual thread
scheduling is platform-dependent and
may vary across different operating
systems and JVM implementations.
A component of Java that decides
which thread to run or execute and
which thread to wait is called a thread
scheduler in Java. In Java, a thread is
only chosen by a thread scheduler if it
is in the runnable state.
4. Synchronization in Java?
Synchronization in Java is the
process that allows only one
thread at a particular time to
complete a given task entirely.
By default, the JVM gives control
to all the threads present in the
system to access the shared
resource, due to which the system
approaches race condition
Synchronization in Java is used to
control access to shared resources
among multiple threads. The
`synchronized` keyword helps in
creating mutually exclusive blocks or
methods, ensuring that only one thread
executes them at a time, preventing
data inconsistency and race conditions.