1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Multithreading
Running multiple threads concurrently within a program
Thread
sequence of instructions in a process
Process
A program in execution with its own memory space
Concurrency
Managing multiple tasks at once (not necessarily parallel)(each thread execution is seperated to others threads execution

Parallelism
Executing multiple tasks simultaneously on multiple cores

Thread class
Class used to create a thread by extending it
interrupt
doesn’t stop a thread ,it sends an interrupt request, to support the request we should check it
Runnable interface
Interface to define a task for a thread (run method)
run()
Method containing code executed by a thread
start()
Method that starts a new thread and calls run()
Thread lifecycle
New, Runnable, Running, Blocked/Waiting, Terminated
sleep()
Pauses a thread for a specified time
join()
makes a thread Wait for another thread to finish execution(block the current thread untilthe other has finished)
yield()
Hints scheduler to give other threads a chance
Daemon thread
Background thread that runs until all user threads finish
User thread
Thread that keeps JVM running
Synchronization
Controlling access to shared resources to avoid conflicts
synchronized keyword
Locks a method or block for thread-safe execution
Critical section
Code accessing shared resources
Race condition
Multiple threads competing to modify shared data causing inconsistency
Deadlock
Threads waiting indefinitely for each other’s resources
Livelock
Threads keep responding but make no progress
Thread safety
Code that works correctly with multiple threads
wait()
Makes thread wait and releases lock
notify()
Wakes one waiting thread
notifyAll()
Wakes all waiting threads
volatile keyword
Ensures visibility of shared variables across threads
Atomic operations
Operations completed without interruption
Executor framework
Manages thread pools and task execution
Thread pool
Group of reusable threads for efficiency
Callable interface
Like Runnable but returns a result
Future object
Holds result of asynchronous computation
Lock
methodes: lock; unlock
volatile
volatile key-word guarantees the change to a field is visible accross threads