Common ways to obtain threads and processes:
- Get the current process ID: ();
- Get the user ID of the current process:();
- Get the current thread ID (1): ().getId();
- Get the current thread ID (2): ();
- Get the application main thread ID: ().getThread().getId());
Common ways to set thread priority
- Set the current thread priority: setThreadPriority(int priority);
- Set the specified thread priority: setThreadPriority(int tid,int priority);
- Get the specified thread priority: getThreadPriority(int tid);
Manage specified processes
- Kill the specified process: killProcess(int pid);
- Send a signal to the specified process: sendSignal(int pid,int singal);
In Android app development, it is often necessary to determine whether the current thread is in the main thread. There are mainly the following ways:
- Use the Looper class to judge:
() != ()
- By viewing the current thread of the Thread class:
() == ().getThread()