Home > Back-end >  Thread. Interrupt () why can have unpark effect ()?
Thread. Interrupt () why can have unpark effect ()?

Time:10-26

 
Public static void aaa () throws InterruptedException {
Thread t=new Thread (new Runnable () {

@ Override
Public void the run () {
Try {
System. Out.println (" ready!!!!!! ");
LockSupport. Park ();//blocking
System. Out.println (" go!!!! ");
} the catch (Exception e) {
e.printStackTrace();
}

}
});
T.s tart ();//start blocking
//3 seconds after performing licenses granted
Thread.sleep (3000);
T.i nterrupt ();
}


The ghost program block released after 3 seconds, print the next go!!!!!! And there is no catch the exception.

CodePudding user response:

Interrupt will actually call interrupt0 interrpt0 is a native method, will the thread. CPP, thread, CPP will call os_linux. CPP, code inside the train of thought is to get roughly to the corresponding Java thread in the operating system, and then set the sign bit, memory barriers, again go to unpark threads, why go to unpark thread? Because if it is a state park, you even points less than CPU time slice, execute/notice about? Thus to achieve a thread unpark communications, source screenshots are as follows:

  • Related