开发者

thread starvation

开发者 https://www.devze.com 2023-01-10 02:43 出处:网络
If I have a big array (400000 elems), a thread with highest priority and a sync read method can we speak as STARVATION if this thread access it and not release the object for a long period of time to

If I have a big array (400000 elems), a thread with highest priority and a sync read method can we speak as STARVATION if this thread access it and not release the object for a long period of time to other threads with a low priority that so starve??

or the starvation is a term concerning only the case where a thread postpone indefin开发者_如何学Citely the release of its object's lock?


Starvation is when the Java runtime (JVM) doesn't allocate time to a thread to execute. This may be due to a poor scheduling algorithm (like green Threads under Solaris, where a for loop from 1 to 1 million doing something CPU intensive wouldn't yield the CPU under Solaris but would under Windows), poor programming practice (not returning from the paint() method in an applet), or a hostile attack (like hitting a host with a denial of service attack where the CPU is busy outside the Java process).

Ref link : http://www.jguru.com/faq/view.jsp?EID=47379


"Starve" can have a lot of meanings. In your case, your threads can be starved of CPU time allocation like others have noted. Also, it can be said that your threads are starved of work.

If for some reason one thread is locking the resource and never releases it, there is a deadlock. There is also a term called "Thread starvation deadlock". In this case, the system becomes deadlock because there are not enough threads (more formally, it occurs if you use a bounded thread pool to execute tasks that are interdependent).

More generally, there can be resource starvation deadlocks, which can occur if you have only a fixed number of resource to perform interdependent tasks concurrently.

In summary, "Starvation" is a overloaded term and can mean many things..


If you ask if starvation happens when thread with lower priority can't acquire lock because threads with higher priority are chosen by scheduler, then yes.


In your situation, one Thread holds a lock while processing data. While that Thread holds the lock, no other Thread can start its work. In that case, it is not Thread starvation. The other Threads cannot start their work because your application explicitly tells them wo wait until the lock is available, which has nothing to do with starvation but with your implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消