Course contentsShow
← Java
Lesson 2630 of 2,87048. Concurrency FundamentalsFree lesson

Inherited Priority from Parent Threads

Discover that new threads inherit their priority from the creating thread unless explicitly set otherwise.

Inherited Priority from Parent Threads

What you'll learn: How new threads automatically inherit their priority from the thread that creates them.

When you create a new thread in Java, you don't always need to explicitly set its priority. By default, the newly created thread inherits the priority of its parent thread—the thread that called the new Thread() constructor.

How Priority Inheritance Works

Think of it like a family trait: children naturally inherit characteristics from their parents unless something explicitly changes them. Similarly, when a thread spawns another thread, the child thread starts with the same priority level as its creator.

This happens automatically in the Thread constructor. If you don't call setPriority(), the new thread simply copies the priority value from Thread.currentThread().getPriority().

Why This Matters

This inheritance mechanism provides sensible defaults. If a high-priority thread creates helper threads, those helpers likely deserve similar attention from the scheduler. Conversely, background threads spawning more background work won't accidentally elevate their priority.

Of course, you can override this inherited value at any time by explicitly calling setPriority() on the new thread before starting it.

Example Without Code

Imagine the main thread runs at priority 5 (the default). When it creates three worker threads without setting their priority, all three start at priority 5 as well. If you later create a thread from one of those workers, it too inherits priority 5. However, if you first raise a worker's priority to 7, any threads it creates will inherit priority 7.

Key Takeaway: New threads automatically inherit their priority from the creating thread, ensuring consistent scheduling behavior unless you explicitly call setPriority() to override the inherited value.