Concurrency Lecture 2 Flashcards
How are thread groups organized together in the JVM?
As a tree structure.
What is the root thread group in the JVM?
The system thread group.
What threads groups are part of the JVM by default?
The system and main thread groups.
What is the code for creating a new thread group?
Not specify the parent, making Main the parent:
ThreadGroup A = new ThreadGroup(“A”);
Specify the parent (In this case, A) :
ThreadGroup B = new ThreadGroup(A, “B”)
What does it return if you look for the parent of the system thread group?
Null.
What happens if you don’t specify a parent for the thread group in declaration?
It’s parent gets set to Main by default.
What is race condition?
When two threads access the same data and change it at the same time. This can cause the data to be set to the wrong thing as both threads do not alter the data, only one will.
When does race condition occur?
What two threads try to access the same thread at once.
What does the thread scheduler do?
It runs the threads. Each thread is run for a short amount of time, and then the scheduler switches the active thread.
There is no guarantee that threads will run in the order they are started in.