Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5096173

Thread.setPriority() doesn't work: The system call fails (EINVAL) on Linux.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • hotspot
    • x86
    • linux



      Name: jl125535 Date: 09/02/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux manu-home.homelinux.net 2.6.8-1.521 #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Calling Thread.setPriority() doesn't work on Linux. From monitoring the system calls,
      (using strace) we see the following system call being made by the JVM when Thread.setPriority() is called.

      sched_setscheduler(ThreadID, SCHED_OTHER, { priority }) = -1 EINVAL (Invalid argument)

      This system call fails, because for the scheduling policy, SCHED_OTHER, the only priority valid is 0. The priorities should be set using the setpriority() and getpriority() system calls on Linux.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Any program which calls Thread.setPriority()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The native thread's priority should be changed.
      ACTUAL -
      system call fails.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) {
       Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Can use JNI to make the right system call.
      (Incident Review ID: 301514)
      ======================================================================

            bobv Bob Vandette (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: