Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Java threads have a tree structure?

I have several threads. And I'd like to create sub-threads in one of them. So I'd like know whether java thread has a tree structure. Or the new created sub-threads is just the sibling of other threads. And What's the resource allocation strategy when these thread are competing for resources? Does the parent thread has higher priority ? Thanks.

Jeff

like image 329
zjffdu Avatar asked Sep 01 '26 13:09

zjffdu


1 Answers

Threads do not strictly have a tree structure. However, you can use ThreadGroups to make a hierarchical nesting of Threads and other ThreadGroups.

I don't believe that there is a hard rule for thread priority inside groups, as each thread can be set separately.

Why do you need "sub-threads"? In my experience, Thread should be avoided in favor of ExecutorService. The service won't give you a hierarchy of stuff easily, but I'm having a hard time thinking of a case where the hierarchy would be useful.

like image 79
user455695 Avatar answered Sep 04 '26 02:09

user455695



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!