2

I'm running a large multithreaded java job on a 64-core machine. The program has been running for days and I would like to change the priority of some threads created by java (not of the main thread), but without cancelling and restarting the program, as that would be a large waste of time and computing resources.

Are there any ways to change thread priority at runtime, from the OS (linux)? I know the renice command in linux can renice the entire process, but I'm looking for a way to change the priority of the created threads at runtime (which doesn't seem to happen with just a renice).

user1111929
  • 6,050
  • 9
  • 43
  • 73

1 Answers1

2

It depends on your Java and Linux version but you can do this:

Make a thread dump of your application. First jps to find the process ID, then jstack for a thread dump.

The dump will contain nids:

"GC task thread#0 (ParallelGC)" prio=10 tid=0x00007f322001f800 nid=0x6bd3 runnable

That's the PID of the thread in hex. You can use printf to convert it to decimal:

printf "%d\n" 0x6bd3

which gives us 27603.

You can now use renice with this PID to change the thread priority.

Sources:

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820