我的布局有一个SurfaceVIEw.有时当我的应用程序从后台切换到前台时,我会得到ANR.我认为原因是主线程被lock方法阻止.
最重要的部分是:
JNI: CheckJNI is off; workarounds are off; pins=1; globals=383 (plus 1
weak)DALVIK THREADS: (mutexes: tll=0 tsl=0 tscl=0 ghl=0)
“main” prio=5 tID=1 WAIT | group=”main” sCount=1 dsCount=0
obj=0x4160fe58 self=0x41529b58 | sysTID=19249 nice=0 sched=0/0
cgrp=apps handle=1074282836 | state=S schedstat=( 140142818375
80057200431 501675 ) utm=11559 stm=2455 core=1 at
java.lang.Object.wait(Native Method)
– waiting on <0x4160ff28> (a java.lang.VMThread) held by tID=1 (main) at java.lang.Thread.parkFor(Thread.java:1205) at
sun.misc.Unsafe.park(Unsafe.java:325) at
java.util.concurrent.locks.LockSupport.park(LockSupport.java:157) at
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:846)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1175)
at
java.util.concurrent.locks.reentrantlock$Nonfairsync.lock(reentrantlock.java:180)
at
java.util.concurrent.locks.reentrantlock.lock(reentrantlock.java:256)
at androID.vIEw.SurfaceVIEw.updateWindow(SurfaceVIEw.java:524) at
androID.vIEw.SurfaceVIEw.onWindowVisibilityChanged(SurfaceVIEw.java:239)
at androID.vIEw.VIEw.dispatchWindowVisibilityChanged(VIEw.java:8004)
at
androID.vIEw.VIEwGroup.dispatchWindowVisibilityChanged(VIEwGroup.java:1077)
at
androID.vIEw.VIEwGroup.dispatchWindowVisibilityChanged(VIEwGroup.java:1077)
at
androID.vIEw.VIEwGroup.dispatchWindowVisibilityChanged(VIEwGroup.java:1077)
at
androID.vIEw.VIEwGroup.dispatchWindowVisibilityChanged(VIEwGroup.java:1077)
at
androID.vIEw.VIEwGroup.dispatchWindowVisibilityChanged(VIEwGroup.java:1077)
at androID.vIEw.VIEwRootImpl.performTraversals(VIEwRootImpl.java:1239)
at androID.vIEw.VIEwRootImpl.doTraversal(VIEwRootImpl.java:1002) at
androID.vIEw.VIEwRootImpl$TraversalRunnable.run(VIEwRootImpl.java:5713)
at
androID.vIEw.Choreographer$CallbackRecord.run(Choreographer.java:761)
at androID.vIEw.Choreographer.doCallbacks(Choreographer.java:574) at
androID.vIEw.Choreographer.doFrame(Choreographer.java:544) at
androID.vIEw.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:747)
at androID.os.Handler.handleCallback(Handler.java:733) at
androID.os.Handler.dispatchMessage(Handler.java:95) at
androID.os.Looper.loop(Looper.java:136) at
androID.app.ActivityThread.main(ActivityThread.java:5120) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:818)
at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:634) at
dalvik.system.NativeStart.main(Native Method)
你看到线程(ID = 1)正在等待线程持有的锁(tID = 1)!怎么会这样?我对此有错误的理解吗?
解决方法:
http://androidxref.com/4.4.2_r2/xref/libcore/libdvm/src/main/java/java/lang/Thread.java
public voID parkFor(long nanos) { VMThread vmt = vmThread; if (vmt == null) { // Running threads should always have an associated vmThread. throw new AssertionError(); } synchronized (vmt) { switch (parkState) { case ParkState.PREEMPTIVELY_UNPARKED: { parkState = ParkState.UNPARKED; break; } case ParkState.UNPARKED: { long millis = nanos / NANOS_PER_MILli; nanos %= NANOS_PER_MILli; parkState = ParkState.PARKED; try { vmt.wait(millis, (int) nanos);//<==//here , maybe it's a normal stack. } catch (InterruptedException ex) { interrupt(); } finally { //.................. }
总结 以上是内存溢出为你收集整理的android – 主线程被Object.wait自行阻止?全部内容,希望文章能够帮你解决android – 主线程被Object.wait自行阻止?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)