Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What defines an "active" thread?

In Java concurrency, what makes a thread "active"? Just the fact that it's not idling? Is a "waiting" or "suspended" thread still considered, technically, active?

like image 727
IAmYourFaja Avatar asked Apr 28 '12 02:04

IAmYourFaja


2 Answers

From what I can tell the term 'active' seems to be used a lot but not ever defined. The ThreadGroup.enumerate() method is documented to:

Copies into the specified array every active thread in this thread group and its subgroups.

and from looking at the source for this, it is checking the Thread.isAlive() method and adding those to the enumerable. From this I deduce that the terms 'active' and 'alive' are interchangeable and 'alive' is defined as:

A thread is alive if it has been started and has not yet died.

like image 93
krock Avatar answered Sep 30 '22 17:09

krock


Take a look at java.lang.Thread.State

In other non Java systems, active equates to "RUNNABLE". A Task/Process/Thread is active if it is able to actively run code. It is suspended if it is not (blocking, etc.)

As Stephen C said, active is being used more as English rather then Java here.

like image 36
edharned Avatar answered Sep 30 '22 17:09

edharned