android.os.Process.getThreadPriority()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中android.os.Process.getThreadPriority()方法的一些代码示例,展示了Process.getThreadPriority()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Process.getThreadPriority()方法的具体详情如下:
包路径:android.os.Process
类名称:Process
方法名:getThreadPriority

Process.getThreadPriority介绍

暂无

代码示例

代码示例来源:origin: facebook/litho

/**
  * Try to raise the priority of {@param threadId} to {@param targetThreadPriority}.
  *
  * @return the original thread priority of the target thread.
  */
 public static int tryRaiseThreadPriority(int threadId, int targetThreadPriority) {
  // Main thread is about to be blocked, raise the running thread priority.
  final int originalThreadPriority = Process.getThreadPriority(threadId);
  boolean success = false;
  while (!success && targetThreadPriority < originalThreadPriority) {
   // Keep trying to increase thread priority of running thread as long as it is an increase.
   try {
    Process.setThreadPriority(threadId, targetThreadPriority);
    success = true;
   } catch (SecurityException e) {
    /*
     From {@link Process#THREAD_PRIORITY_DISPLAY}, some applications can not change
     the thread priority to that of the main thread. This catches that potential error
     and tries to set a lower priority.
    */
    targetThreadPriority += Process.THREAD_PRIORITY_LESS_FAVORABLE;
   }
  }
  return originalThreadPriority;
 }
}

代码示例来源:origin: facebook/litho

/**
 * Try to raise the priority of {@param threadId} to the priority of the calling thread
 *
 * @return the original thread priority of the target thread.
 */
public static int tryInheritThreadPriorityFromCurrentThread(int threadId) {
 return tryRaiseThreadPriority(threadId, Process.getThreadPriority(Process.myTid()));
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getThreadPriority_notSet_returnsZero() {
 assertThat(android.os.Process.getThreadPriority(123)).isEqualTo(0);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getThreadPriority_returnsThreadPriority() {
 android.os.Process.setThreadPriority(123, android.os.Process.THREAD_PRIORITY_VIDEO);
 assertThat(android.os.Process.getThreadPriority(123))
   .isEqualTo(android.os.Process.THREAD_PRIORITY_VIDEO);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getThreadPriority_currentThread_returnsCurrentThreadPriority() {
 android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
 assertThat(android.os.Process.getThreadPriority(/*tid=*/ 0))
   .isEqualTo(android.os.Process.THREAD_PRIORITY_AUDIO);
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void setThreadPriorityOneArgument_setsCurrentThreadPriority() {
  android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

  assertThat(android.os.Process.getThreadPriority(android.os.Process.myTid()))
    .isEqualTo(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
 }
}

相关文章