Threads Flashcards
What are the possible states of a thread in Java?
New, Runnable, Waiting, Timed Waiting, Blocked, Terminated
What state does a thread enter when it is created but not yet started?
New
What happens when a thread is in the Runnable state?
It is considered to be executing its task
What is the Waiting state in a thread life cycle?
A state where a runnable thread waits for another thread to perform a task
What is the Timed Waiting state?
A state where a runnable thread waits for a specified interval of time
When does a thread return to the Runnable state from Timed Waiting?
When the time interval expires or when it is notified by another thread
What causes a thread to enter the Blocked state?
When it attempts a task that cannot be completed immediately
What is the Terminated state?
A state when a runnable thread successfully completes its task or terminates
What does the JVM see when a thread is in the Runnable state?
It sees only the Runnable state, not the underlying Ready and Running states
What is thread scheduling in an operating system?
The process that determines which thread runs next based on priorities
What is a thread’s priority in Java?
A value that helps determine the order in which threads are scheduled
True or False: Higher-priority threads are guaranteed to execute before lower-priority threads.
False
What is timeslicing in the context of thread execution?
A method that allows threads of equal priority to share a processor
What is the purpose of the Runnable interface?
To specify a task that can execute concurrently with other tasks
What does the Executor interface do?
It manages a group of threads called a thread pool to execute Runnables