Threads Flashcards
What is multithreading?
It is the process of executing multiple threads simultaneously to maximize the utilization of the CPU
In what ways can you create a thread?
Create a thread by extending a class from the Thread class or implementing the runnable interface
List the methods of the Thread class and Runnable interface
run() start() sleep() join() getName() setName() setPriority() getPriority() stop() resume()
Explain the lifecycle of a thread
New Thread - When the thread is created but not started
Runnable - Runnable state after invocation
Running - Doing the task it was assigned
Non-Runnable/Blocked
Terminated - When the thread has completed its task
What is a deadlock?
Deadlock occurs when two threads are waiting on a locked objects from each other and can never continue
What is the synchronized keyword?
It is a keyword that allows an object to tell threads to access it one at a time