Questions tagged [thread-priority]

Thread priorities specify the relative priority of one thread versus another.

Thread priorities specify the relative priority of one thread versus another.

Threads are scheduled for execution based on their priority. The scheduling algorithm used to determine the order of thread execution varies with each operating system.

All threads with the same priority are treated as equal - the scheduler assigns time slices in a round-robin fashion to all threads with the highest priority. If none of these threads are ready to run, the scheduler assigns time slices in a round-robin fashion to all threads with the next highest priority.

A round robin scheduler runs through equal priority threads in the order they are stored in memory. This helps prevents deadlock if multiple threads have the same priority, although thread safety and performance can be compromised.

References

217 questions
77
votes
7 answers

What is the 'realtime' process priority setting for?

From what I've read in the past, you're encouraged not to change the priority of your Windows applications programmatically, and if you do, you should never change them to 'Realtime'. What does the 'Realtime' process priority setting do, compared to…
Chris S
  • 62,476
  • 49
  • 214
  • 238
61
votes
5 answers

Portable way of setting std::thread priority in C++11

What is the correct way in the post C++11 world for setting the priority of an instance of std::thread Is there a portable way of doing this that works at least in Windows and POSIX (Linux) environments? Or is it a matter of getting a handle and…
Gerdiner
  • 1,135
  • 3
  • 12
  • 19
40
votes
8 answers

Java Executors: how can I set task priority?

Is there a possibility to set priority to tasks which are executed by Executors? I've found some statements in JCIP about it's possible but I cannot find any example and I cannot find anything related in docs. From JCIP: An execution policy…
Roman
  • 59,060
  • 84
  • 230
  • 322
28
votes
5 answers

Setting priority to Java's threads

I have a program that runs in a few threads. The main thread shares an object with the other threads and in the main I have a call to: synchronized(obj){ do stuff } I have a suspicion that the main thread is starved and isn't getting access to…
Guy
  • 12,478
  • 25
  • 61
  • 86
24
votes
6 answers

Why *not* change the priority of a ThreadPool (or Task) thread?

There are many places across the web and Stack Overflow where one is discouraged from changing the priority of a ThreadPool thread or TPL Task. In particular: "You have no control over the state and priority of a thread pool thread." "The runtime…
Glenn Slayden
  • 14,572
  • 3
  • 90
  • 97
24
votes
3 answers

Do Linux JVMs actually implement Thread priorities?

Wrote a quick Java proggy to spawn 10 threads with each priority and calculate pi (4*atan(1) method) with BigDecimals 500,000 times each, join on each thread and report the elapsed time for run method. Yeah, prob'ly not the best example, but…
Jé Queue
  • 9,627
  • 12
  • 50
  • 60
17
votes
2 answers

Is there a way to set a Web Worker to low priority?

I am thinking of using Web Workers to provide some background functionality while a user is browsing my website (that's what Web Workers are for, right?). However, I don't want to take the risk of compromising the user experience by causing laggy…
tunnuz
  • 21,380
  • 29
  • 86
  • 124
13
votes
1 answer

Changing thread priority doesn't have an effect

I'm trying to change priority of main thread using android.os.Process.setThreadPriority(). I have log messages before and after priority changing, here is code: public class TestActivity extends Activity { public final String…
Eugene Chumak
  • 3,166
  • 7
  • 28
  • 50
13
votes
4 answers

C linux pthread thread priority

My program has one background thread that fills and swaps the back buffer of a double buffer implementation. The main thread uses the front buffer to send out data. The problem is the main thread gets more processing time on average when I run the…
eat_a_lemon
  • 3,178
  • 10
  • 30
  • 46
13
votes
1 answer

Are there any cases where priority inheritance is not desirable?

I understand what priority inheritance is. I also understand, from the Mars Pathfinder's system reset issue, that most of the time, depending upon the criticality of the operation, it is good to enable/implement priority inheritance. However, are…
Anish Ramaswamy
  • 2,248
  • 3
  • 25
  • 62
12
votes
8 answers

Sporadic problems in running a multi-threaded Java project in Win7

I am working on a project that is both memory and computationally intensive. A significant portion of the execution utilizes multi-threading by a FixedThreadPool. In short; I have 1 thread for fetching data from several remote locations (using URL…
posdef
  • 6,196
  • 10
  • 40
  • 85
12
votes
11 answers

How can you ensure in java that a block of code can not be interrupted by any other thread

exampl: new Thread(new Runnable() { public void run() { while(condition) { *code that must not be interrupted* *some more code* } } }).start(); SomeOtherThread.start(); YetAntherThread.start(); How can you ensure that…
Richard
12
votes
6 answers

Java multithreading - thread priority

Can anybody explain how thread priority works in java. The confusion here is if java does'nt guarantee the implementation of the Thread according to its priority then why is this setpriority() function used for. My code is as follows : public class…
Neal
  • 527
  • 2
  • 12
  • 22
9
votes
5 answers

Java multithreading in CPU load

I have a bit of an issue with an application running multiple Java threads. The application runs a number of working threads that peek continuously at an input queue and if there are messages in the queue they pull them out and process them. Among…
8
votes
5 answers

Java Garbage Collection thread priority

I have been asked in an interview the following question: "What is the default priority of the Garbage Collection thread?" I know we cannot force a GC or change its priority, though I never heard about its default priority. Does anyone know?
user689842
1
2 3
14 15