linux java 线程状态_进程 / Linux 进程 / Java 线程 状态

本文介绍了进程、Linux进程和Java线程的状态。进程有就绪、运行和阻塞状态,且就绪态和运行态可相互转换。Linux进程有R、D、S、Z、T等状态。Java线程有新建、可运行、阻塞、无限期等待、限期等待和死亡等状态,并说明了各状态的进入和退出方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

进程 / Linux 进程 / Java 线程 状态

进程状态

0894b3e71ebc2dd436008d7fae7fb987.png

就绪状态(ready):等待被调度

运行状态(running)

阻塞状态(waiting):等待资源

应该注意以下内容:

只有就绪态和运行态可以相互转换,其它的都是单向转换。就绪状态的进程通过调度算法从而获得 CPU 时间,转为运行状态;而运行状态的进程,在分配给它的 CPU 时间片用完之后就会转为就绪状态,等待下一次调度。

阻塞状态是缺少需要的资源从而由运行状态转换而来,但是该资源不包括 CPU 时间,缺少 CPU 时间会从运行态转换为就绪态。

Linux 进程状态

5f577260d6f4d73e6779d02e5fe25c05.png

R running or runnable (on run queue) 正在执行或者可执行,此时进程位于执行队列中。

D uninterruptible sleep (usually I/O) 不可中断阻塞,通常为 IO 阻塞。

S interruptible sleep (waiting for an event to complete) 可中断阻塞,此时进程正在等待某个事件完成。

Z zombie (terminated but not reaped by its parent) 僵死,进程已经终止但是尚未被其父进程获取信息。

T stopped (either by a job control signal or because it is being traced) 结束,进程既可以被作业控制信号结束,也可能是正在被追踪。

Java 线程状态

130f401547764f991f8a977dd2aada91.png

新建(New)

创建后尚未启动。

可运行(Runnable)

可能正在运行,也可能正在等待 CPU 时间片。

包含了操作系统线程状态中的 Running 和 Ready。

阻塞(Blocked)

等待获取一个排它锁,如果其线程释放了锁就会结束此状态。

无限期等待(Waiting)

等待其它线程显式地唤醒,否则不会被分配 CPU 时间片。

进入方法

退出方法

没有设置 Timeout 参数的 Object.wait() 方法

Object.notify() / Object.notifyAll()

没有设置 Timeout 参数的 Thread.join() 方法

被调用的线程执行完毕

LockSupport.park() 方法

LockSupport.unpark(Thread)

限期等待(Timed Waiting)

无需等待其它线程显式地唤醒,在一定时间之后会被系统自动唤醒。

调用 Thread.sleep() 方法使线程进入限期等待状态时,常常用“使一个线程睡眠”进行描述。

调用 Object.wait() 方法使线程进入限期等待或者无限期等待时,常常用“挂起一个线程”进行描述。

睡眠和挂起是用来描述行为,而阻塞和等待用来描述状态。

阻塞和等待的区别在于,阻塞是被动的,它是在等待获取一个排它锁。而等待是主动的,通过调用 Thread.sleep() 和 Object.wait() 等方法进入。

进入方法

退出方法

Thread.sleep() 方法

时间结束

设置了 Timeout 参数的 Object.wait() 方法

时间结束 / Object.notify() / Object.notifyAll()

设置了 Timeout 参数的 Thread.join() 方法

时间结束 / 被调用的线程执行完毕

LockSupport.parkNanos() 方法

LockSupport.unpark(Thread)

LockSupport.parkUntil() 方法

LockSupport.unpark(Thread)

死亡(Terminated)

可以是线程结束任务之后自己结束,或者产生了异常而结束。

参考资料

FAILED: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art /bin/bash -c "(mkdir -p out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/ ) && (rm -f out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.oat out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm//*.art.rel ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.oat ) && (rm -f out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm//*.art.rel ) && (ANDROID_LOG_TAGS=\"*:e\" out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx64m --compiler-filter=speed-profile --profile-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.prof --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telephony-base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/voip-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.base-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.hidl.manager-V1.0-java_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/framework-oahl-backward-compatibility_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/android.test.base_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-ims-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-telecom-common_intermediates/javalib.jar --dex-file=out/target/common/obj/JAVA_LIBRARIES/mediatek-cta_intermediates/javalib.jar --dex-location=/system/framework/mediatek-common.jar --dex-location=/system/framework/mediatek-framework.jar --dex-location=/system/framework/mediatek-telephony-common.jar --dex-location=/system/framework/mediatek-telephony-base.jar --dex-location=/system/framework/core-oj.jar --dex-location=/system/framework/core-libart.jar --dex-location=/system/framework/conscrypt.jar --dex-location=/system/framework/okhttp.jar --dex-location=/system/framework/bouncycastle.jar --dex-location=/system/framework/apache-xml.jar --dex-location=/system/framework/ext.jar --dex-location=/system/framework/framework.jar --dex-location=/system/framework/telephony-common.jar --dex-location=/system/framework/voip-common.jar --dex-location=/system/framework/ims-common.jar --dex-location=/system/framework/android.hidl.base-V1.0-java.jar --dex-location=/system/framework/android.hidl.manager-V1.0-java.jar --dex-location=/system/framework/framework-oahl-backward-compatibility.jar --dex-location=/system/framework/android.test.base.jar --dex-location=/system/framework/mediatek-ims-common.jar --dex-location=/system/framework/mediatek-telecom-common.jar --dex-location=/system/framework/mediatek-cta.jar --oat-symbols=out/target/product/p12_k37mv1_bsp/symbols/system/framework/arm/boot.oat --oat-file=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.oat --oat-location=/system/framework/arm/boot.oat --image=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/boot.art --base=0x70000000 --instruction-set=arm --instruction-set-variant=cortex-a53 --instruction-set-features=default --android-root=out/target/product/p12_k37mv1_bsp/system --runtime-arg -Xnorelocate --compile-pic --no-generate-debug-info --generate-build-id --multi-image --no-inline-from=core-oj.jar --abort-on-hard-verifier-error --abort-on-soft-verifier-error --no-abort-on-soft-verifier-error --generate-mini-debug-info || ( echo \"ERROR: Dex2oat failed to compile a boot image. It is likely that the boot classpath is inconsistent. Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS=\"--runtime-arg -verbose:verifier\" to see verification errors.\" ; false ) && ANDROID_LOG_TAGS=\"*:e\" ANDROID_ROOT=out/target/product/p12_k37mv1_bsp/system ANDROID_DATA=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ out/host/linux-x86/bin/patchoatd --input-image-location=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art --output-image-relocation-directory=out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/arm/ --instruction-set=arm --base-offset-delta=0x10000000 )" patchoatd E 08-01 17:03:32 1204514 1204514 image_space.cc:1761] Could not create image space with image file 'out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot.art'. Attempting to fall back to imageless running. Error was: Failed to mmap at expected address, mapped at 0x72f9d8a00000 instead of 0x7057a000 patchoatd E 08-01 17:03:32 1204514 1204514 image_space.cc:1761] Attempted image: out/target/product/p12_k37mv1_bsp/dex_bootjars/system/framework/boot-framework.art patchoatd E 08-01 17:03:32 1204514 1204514 runtime.cc:1290] Dex file fallback disabled, cannot continue without image. patchoatd E 08-01 17:03:32 1204514 1204514 patchoat.cc:485] Unable to initialize runtime [ 32% 292/886] //frameworks/base/media/jni:libmedia2_jni link libmedia2_jni.so ninja: build stopped: subcommand failed. 17:03:37 ninja failed with: exit status 1
最新发布
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值