Android – the main thread is blocked by object.wait?

My layout has a surfaceview. Sometimes when my application switches from the background to the foreground, I get ANR. I think the reason is that the main thread is blocked by the lock method

The most important part is:

You see that the thread (id = 1) is waiting for the lock held by the thread (TID = 1)! How did this happen? Do I have a wrong understanding of this?

resolvent:

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 {
                //..................
                }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>