简体   繁体   English

我如何才能使一个线程从多个运行中最大化(在等待队列中的最短时间)?

[英]How can i make one thread out of several run for maximum time(minimum time in waiting queue)?

So, I am building an application(for machine simulator). 因此,我正在构建一个应用程序(用于机器模拟器)。 It consists of 8 threads.Out of which one thread represents main machine. 它由8个线程组成,其中一个线程代表主机。 I want this thread to run for maximum time ie maximum CPU time should be given to this thread by thread scheduler. 我希望此线程运行最长的时间,即线程调度程序应为该线程分配最大的CPU时间。 If I put this thread to sleep it should have very less waiting time. 如果我让该线程进入睡眠状态,则等待时间应该非常短。 One of the way to achieve this would to dedicate a processor core to this thread but thread affinity can not be set in JAVA. 实现此目的的一种方法是将处理器内核专用于该线程,但是无法在JAVA中设置线程关联。 The only option I see for doing this is to set this thread's priority to MAXIMUM. 我看到的唯一选择是将此线程的优先级设置为MAXIMUM。 is there any other way to achieve this? 还有其他方法可以实现这一目标吗?

使用Thread.setPriority()将主线程的优先级设置为Thread.MAX_PRIORITY,将其他线程的优先级设置为Thread.MIN_PRIORITY;。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM