android:Thread.interrupt()

本文介绍如何在Java线程中使用isInterrupted方法来判断并控制线程退出,包括在while循环中的应用和捕获InterruptedException的退出方式。

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

使用前提:

  1. thread中要进行while操作时。

  2. 需要控制thread退出。


使用方法:

  1. this.isInterrupted() 判断退出。接收到 mMyThread1.interrupt();则退出。

    private class MyThread1 extends Thread {
        @Override
        public void run() {
                while (!this.isInterrupted()) {
                    // do our things
                }
        }
    }
    
  2. catch InterruptedException 退出, 同样接收到 mMyThread1.interrupt();则退出

    private class MyThread2 extends Thread {
        @Override
        public void run() {
            while (true) {
                // do our things
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        }
    }
    

转载自:http://blog.youkuaiyun.com/wuyuxing24/article/details/45342049

Process pipe failed 2025-06-05 21:00:33.745 22340-22371 ConfigStore com.example.diaryapp I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 2025-06-05 21:00:33.745 22340-22371 ConfigStore com.example.diaryapp I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 2025-06-05 21:00:33.745 22340-22371 OpenGLRenderer com.example.diaryapp I Initialized EGL, version 1.4 2025-06-05 21:00:33.745 22340-22371 OpenGLRenderer com.example.diaryapp D Swap behavior 1 2025-06-05 21:00:33.746 22340-22371 EGL_adreno com.example.diaryapp E CreateContext rcMajorVersion:3, minorVersion:2 2025-06-05 21:00:33.754 22340-22371 EGL_adreno com.example.diaryapp D eglCreateContext: 0x7f2e2da30120: maj 3 min 2 rcv 3 2025-06-05 21:00:33.754 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:33.754 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:33.781 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:33.781 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:33.782 22340-22371 vndksupport com.example.diaryapp D Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace. 2025-06-05 21:00:33.782 22340-22371 vndksupport com.example.diaryapp D Loading /vendor/lib64/hw/gralloc.gmin.so from current namespace instead of sphal namespace. 2025-06-05 21:00:33.786 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:33.786 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2da27e00, error=EGL_BAD_MATCH 2025-06-05 21:00:34.214 22340-22340 xample.diaryap com.example.diaryapp W Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (light greylist, reflection) 2025-06-05 21:00:34.214 22340-22340 xample.diaryap com.example.diaryapp W Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (light greylist, reflection) 2025-06-05 21:00:34.214 22340-22340 xample.diaryap com.example.diaryapp W Accessing hidden method Landroid/os/Trace;->traceCounter(JLjava/lang/String;I)V (light greylist, reflection) 2025-06-05 21:00:39.439 22340-22401 ProfileInstaller com.example.diaryapp D Installing profile for com.example.diaryapp 2025-06-05 21:00:40.016 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:40.016 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:40.023 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:40.023 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2db3cb80, error=EGL_BAD_MATCH 2025-06-05 21:00:40.026 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@b266666 2025-06-05 21:00:40.267 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:40.267 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:40.283 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:40.283 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2db3cc80, error=EGL_BAD_MATCH 2025-06-05 21:00:40.292 22340-22340 Glide com.example.diaryapp W Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored 2025-06-05 21:00:42.727 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@7575cb3 2025-06-05 21:00:42.763 22340-22345 xample.diaryap com.example.diaryapp I Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int) 2025-06-05 21:00:42.780 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:42.780 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:42.794 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:42.794 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2dbdb280, error=EGL_BAD_MATCH 2025-06-05 21:00:50.659 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:50.659 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:50.673 22340-22340 xample.diaryap com.example.diaryapp W Accessing hidden field Landroid/view/View;->mAccessibilityDelegate:Landroid/view/View$AccessibilityDelegate; (light greylist, reflection) 2025-06-05 21:00:50.675 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:50.675 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2dbdb300, error=EGL_BAD_MATCH 2025-06-05 21:00:52.086 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@d5d171c 2025-06-05 21:00:52.186 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:52.186 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:52.204 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:52.204 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d0afd00, error=EGL_BAD_MATCH 2025-06-05 21:00:53.766 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:53.766 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:53.776 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:53.776 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d337180, error=EGL_BAD_MATCH 2025-06-05 21:00:58.199 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:00:58.199 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:00:58.220 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:00:58.220 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2dbdb300, error=EGL_BAD_MATCH 2025-06-05 21:01:01.788 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@bf7a046 2025-06-05 21:01:01.863 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:01.863 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:01.880 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:01.880 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d222f00, error=EGL_BAD_MATCH 2025-06-05 21:01:04.247 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:04.247 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:04.268 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:04.268 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2dbdb300, error=EGL_BAD_MATCH 2025-06-05 21:01:06.508 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@58e8cd8 2025-06-05 21:01:06.613 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:06.613 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:06.633 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:06.633 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d222f00, error=EGL_BAD_MATCH 2025-06-05 21:01:07.985 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:07.985 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:07.993 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:07.993 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2db3c000, error=EGL_BAD_MATCH 2025-06-05 21:01:07.996 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@d24a3e0 2025-06-05 21:01:08.020 22340-22349 System com.example.diaryapp W A resource failed to call close. 2025-06-05 21:01:08.021 22340-22349 chatty com.example.diaryapp I uid=10062(com.example.diaryapp) FinalizerDaemon identical 2 lines 2025-06-05 21:01:08.021 22340-22349 System com.example.diaryapp W A resource failed to call close. 2025-06-05 21:01:08.038 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:08.038 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:08.057 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:08.057 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2c09d580, error=EGL_BAD_MATCH 2025-06-05 21:01:09.873 22340-22340 ActivityThread com.example.diaryapp W handleWindowVisibility: no activity for token android.os.BinderProxy@4e83cf6 2025-06-05 21:01:09.914 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:09.914 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:09.934 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:09.934 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d9c8580, error=EGL_BAD_MATCH 2025-06-05 21:01:11.614 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:11.614 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:11.629 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:11.629 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e1d95f280, error=EGL_BAD_MATCH 2025-06-05 21:01:13.193 22340-22371 OpenGLRenderer com.example.diaryapp D endAllActiveAnimators on 0x7f2e1d16d900 (RippleDrawable) with handle 0x7f2e2db44560 2025-06-05 21:01:13.213 22340-22371 EGL_adreno com.example.diaryapp E [getAttribValue] Bad attribute idx 2025-06-05 21:01:13.213 22340-22371 EGL_adreno com.example.diaryapp D eglGetConfigAttrib: bad attrib 0x3339 2025-06-05 21:01:13.231 22340-22371 EGL_adreno com.example.diaryapp E tid 22371: eglSurfaceAttrib(1615): error 0x3009 (EGL_BAD_MATCH) 2025-06-05 21:01:13.231 22340-22371 OpenGLRenderer com.example.diaryapp W Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2e2db3c680, error=EGL_BAD_MATCH
最新发布
06-06
Android平台时MTK,以下是播放杂音视频时的log03-12 13:44:54.038 3370 3370 D AudioTrack: start(84): 0xb400006dfdcac570, prior state:STATE_PAUSED 03-12 13:44:54.046 925 925 D AudioFlinger_Threads: addTrack_l() mActiveSRCTrackIdVector.size() = 0, before mActiveSRCTrackIdVector.push_back(94) 03-12 13:44:54.047 925 1349 D StreamHalAidl: setParameters: parameters: "NoAudioTrack=0" 03-12 13:44:54.047 925 1349 D StreamHalAidl: setParameters: parameters: NoAudioTrack=0 03-12 13:44:54.474 925 1349 D AudioFlinger_Threads: stream out write(0) process 424 ms 03-12 13:44:54.496 925 1349 W AudioFlinger_Threads: write blocked for 446 msecs, 32 delayed writes, thread 13 03-12 13:44:54.496 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_track_id94_out_port84.io13.flag6.wav, current size: 0 03-12 13:44:54.496 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_resampler_id94_in_io13.pid925.tid1349.wav, current size: 0 03-12 13:44:54.497 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_resampler_id94_out_io13.pid925.tid1349.wav, current size: 0 03-12 13:44:54.497 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_mixer_io13_out_pid925.tid1349.wav, current size: 0 03-12 13:44:54.497 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_writer_io13_out_pid925.tid1349_20250312-134454.wav, current size: 8192 03-12 13:44:54.498 925 1349 D AudioFlinger_Threads: 0xb4000077b2add7c0: threadLoop_write write data to hw, mixerStatus 2, muted count 47 03-12 13:44:54.614 3370 9315 D AudioTrack: stop(84): 0xb400006dfdcac570, prior state:STATE_ACTIVE 03-12 13:44:54.614 3370 9315 D AudioTrack: stop(84): called with 247808 frames delivered 03-12 13:44:54.616 3370 9315 D AudioTrackShared: this(0xb400006e8dc8c5f0), mCblk(0x6fd92ee000), front(492248), mIsOut 1, interrupt() FUTEX_WAKE 03-12 13:44:54.617 3370 9315 D AudioTrack: stop(84): 0xb400006dfdcac570 stop done 03-12 13:44:54.617 3370 9315 D AudioTrack: flush(84): 0xb400006dfdcac570, prior state:STATE_STOPPED 03-12 13:44:54.618 3370 9315 D AudioTrack: stop(84): 0xb400006dfdcac570, prior state:STATE_FLUSHED 03-12 13:44:54.624 3370 9310 D AudioTrack: start(84): 0xb400006dfdcac570, prior state:STATE_FLUSHED 03-12 13:44:54.656 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_track_id94_out_port84.io13.flag6_20250312-134454.wav, current size: 22576 03-12 13:44:54.656 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_resampler_id94_in_io13.pid925.tid1349_20250312-134454.wav, current size: 45152 03-12 13:44:54.656 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_resampler_id94_out_io13.pid925.tid1349_20250312-134454.wav, current size: 49152 03-12 13:44:54.657 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_mixer_io13_out_pid925.tid1349_20250312-134454.wav, current size: 49152 03-12 13:44:54.657 925 1349 D AudioFlinger_Threads: logDumpSize, id: 94, port84_13, dump file /data/debuglogger/audio_dump/af_writer_io13_out_pid925.tid1349_20250312-134454.wav, current size: 57344 03-12 13:44:58.878 3370 3370 D AudioTrack: pause(84): 0xb400006dfdcac570, prior state:STATE_ACTIVE 03-12 13:44:58.882 3370 3370 D AudioTrackShared: this(0xb400006e8dc8c5f0), mCblk(0x6fd92ee000), front(680787), mIsOut 1, interrupt() FUTEX_WAKE 03-12 13:44:58.882 3370 9315 D AudioTrackShared: obtainBuffer() interrupted by client 03-12 13:44:58.907 925 1349 D AudioFlinger_Threads: 0xb4000077b2add7c0:threadLoop_write write muted data to hw, mixerStatus 0 start, mId 13, mBytesWritten 1695744
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值