Throttling CPU/Memory usage of a Thread in Java?

前端 未结 9 2283
借酒劲吻你
借酒劲吻你 2020-12-07 13:00

I\'m writing an application that will have multiple threads running, and want to throttle the CPU/memory usage of those threads.

There is a similar question for C++,

9条回答
  •  天涯浪人
    2020-12-07 13:31

    You can assign different priorities to the threads so the most relevant thread get scheduled more often.

    Look at this answer to see if that helps.

    When all the running thread have the same priority they may run like this:

    t1, t2, t3,     t1, t2, t3,   t1, t2, t3
    

    When you assign a different priority to one of them it may look like:

    t1, t1, t1, t1,    t2,    t1, t1, t1 t3.
    

    That is, the first thread runs "more often" that the rest.

提交回复
热议问题