Simple thread blocking

Simple Thread Blocking Method

yeild()

When this method is called, it tells the thread dispatching mechanism that I can execute without being busy, although this scenario may not necessarily execute.

Local method
public static native void yield();

join()

When this method is called, threads A call B.join() on thread B, and threads A are suspended until B.isAlive() returns false.We can also call the interrupt method on our own and the terminal join () method

public final void join() throws InterruptedException {
        this.join(0L);
}
//Default incoming parameter 0L
public final synchronized void join(long var1) throws InterruptedException {
        long var3 = System.currentTimeMillis();//Get Current Time Assumption 1513000171971
        long var5 = 0L;
        if (var1 < 0L) {
            throw new IllegalArgumentException("timeout value is negative");
        } else {
            if (var1 == 0L) { //The default is 0, so enter this method
                while(this.isAlive()) { //If this thread has always been alive, it will wait
                    this.wait(0L);
                }
            } else {//If there is a value, it represents a timeout parameter, and if it exceeds that time, it returns itself if it has not finished
                while(this.isAlive()) {
                    //Let's assume var1=1000
                    long var7 = var1 - var5; //The first var5 is 0, var1==var7==1000
                    if (var7 <= 0L) {//1000<=0L-—>false
                        break;//Until run to break
                    }
                    this.wait(var7);//Waiting for 1000L
                    //var5 = 1513000191262-1513000171971=19291
                    var5 = System.currentTimeMillis() - var3;
                }               
            }
        }
    }

Sleep()

public static native void sleep(long var0) throws InterruptedException;

    public static void sleep(long var0, int var2) throws InterruptedException {
        if (var0 < 0L) {
            throw new IllegalArgumentException("timeout value is negative");
        } else if (var2 >= 0 && var2 <= 999999) {
            if (var2 >= 500000 || var2 != 0 && var0 == 0L) {
                ++var0;
            }

            sleep(var0);
        } else {
            throw new IllegalArgumentException("nanosecond timeout value out of range");
        }
    }

Posted on Sat, 13 Jun 2020 12:16:39 -0400 by loveccb