You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A thread is the smallest unit of execution that can be scheduled by the OS
A process is a collection of threads executing in a shared environment - sharing same memoery space and communicate with each other.
Single threaded process is one which contains exactly one thread
Multi threaded process is one which contains one or more threads
Static variables enable us to perform multithreaded tasks. If one thread updates a static variables, than another thread can access this information immediately.
Task is a single unit of work performed by a thread.
🟥 7.1.1 Distinguishing Thread Types
All java applications in this book have been multi-threaded!
System thread is created by JVM and runs in the background of the application.
E.g. garbage collection is a system thread
If a system thread encounters a problem it generates a Java Error rather than Exception
User-defined thread is created by the developer to achieve a specific task.
We are often not concerned with system threads,
🟥 7.1.2 Understanding Thread Concurrency
Concurrency is the property of executing multiple threads and processes at the same time.
We can achieve concurrency with single core CPUs, in fact we often have more threads than cores.
Operating Systems use a thread scheduler to determine which threads should be currently executing.
A thread scheduler may employ a round-robin schedule.
A thread is given an allotted time, if the task does not finish within that time then a context switch occurs.
A context switch is the process of storing a thread's current state.
Thread priority is a numeric value associated with the thread and is used by the thread scheduler to determine which threads should be executed.
🟥 7.1.3 Introducing Runnable
java.lang.Runnable is a functional interface which takes no arguments and returns no data: