Java 中线程优先级到底做什么
What exactly does thread priority do in Java
我目前正在做一个用 java 编写的 android 项目。
我有一个仪表板,它从 cloudant 数据库查询数据并在图形上呈现数据。然而,数据必须在收到时进行处理。
我有 4 个 AsyncTasks,它们同时(或应该)处理 doInBackground Override 方法中接收到的数据。这个过程很慢,我试过这条线
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
在每个 AsyncTask 中。
但是,4个AsynkTasks好像都是一个接一个发生,是不是线程的优先级改成了max?更改线程优先级时,是否会停止所有其他线程并仅继续执行一个线程直到完成?
发件人:https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html
Every thread has a priority. Threads with higher priority are executed
in preference to threads with lower priority. Each thread may or may
not also be marked as a daemon. When code running in some thread
creates a new Thread object, the new thread has its priority initially
set equal to the priority of the creating thread, and is a daemon
thread if and only if the creating thread is a daemon.
(注意:此信息是通过在 google 中搜索 "java Thread.MAX_PRIORITY" 并查看顶部结果找到的)
Every thread has a priority. Threads with higher priority are executed
in preference to threads with lower priority. ... When code running in
some thread creates a new Thread object, the new thread has its
priority initially set equal to the priority of the creating thread.
从字面上看,这只是一个提示,告诉调度程序大致按照什么顺序执行线程。它可以而且很可能会忽略你。
如果您已将所有线程的优先级设置为最大,这与将它们保留为默认值实际上是一样的。正如你可能不得不告诉你的老板,如果一切都是最重要的,那么没有什么是最重要的:)
我目前正在做一个用 java 编写的 android 项目。
我有一个仪表板,它从 cloudant 数据库查询数据并在图形上呈现数据。然而,数据必须在收到时进行处理。
我有 4 个 AsyncTasks,它们同时(或应该)处理 doInBackground Override 方法中接收到的数据。这个过程很慢,我试过这条线
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
在每个 AsyncTask 中。
但是,4个AsynkTasks好像都是一个接一个发生,是不是线程的优先级改成了max?更改线程优先级时,是否会停止所有其他线程并仅继续执行一个线程直到完成?
发件人:https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html
Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.
(注意:此信息是通过在 google 中搜索 "java Thread.MAX_PRIORITY" 并查看顶部结果找到的)
Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. ... When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread.
从字面上看,这只是一个提示,告诉调度程序大致按照什么顺序执行线程。它可以而且很可能会忽略你。
如果您已将所有线程的优先级设置为最大,这与将它们保留为默认值实际上是一样的。正如你可能不得不告诉你的老板,如果一切都是最重要的,那么没有什么是最重要的:)