天天看點

Happens-before

program order rule: each action in a thread happens-before every action in that thread that comes later in the program order.

monitor lock rule: an unlock on a monitor lock happens-before every subsequent lock on that same monitor lock.

volatile variable rule: a write to a volatile field happens-before every subsequent read of that same field.

thread start rule: a call to thread.start on a thread happens-before every action in the started thread.

thread termination rule: any action in a thread happens-before any other thread detects that thread has terminated, either by successfully return from thread.join or by thread.isalive returning false.

interruption rule: a thread calling interrupt on another thread happens-before the interrupted thread detects the interrupt(either by having interruptedexception thrown, or invoking isinterrupted or interrupted).

finalizer rule: the end of a constructor for an object happens-before the start of the finalizer for that object.

transitivity: if a happens-before b, and b happens-before c, then a happens-before c.