This question is about the one of the heuristics Java uses of biased locking. The next paragraph is for future readers; I suspect anyone who can answer this question can safely skip it.
As far as I understand, once upon a time, people noticed that Java has lots of classes that are thread safe, but whose instances tend to be used by only one thread, so Sun introduced biased locking to take advantage of that. The trouble is, if you "guess wrong" and try to bias a lock that needs to be used from two threads, the bias needs to be undone ("revoked") even if there is no contention, and this is so expensive that the JVM tries hard to avoid it, even if it means sometimes missing out on situations where biased locking could have been a net win.
I also know that sometimes the JVM decides the do a "bulk" re-bias, and migrate many all locks of a certain type to a different thread. This question is NOT about that. For the purpose of this question, suppose I only have two threads and a single lock. (The real situation is more complicated and involves thread pools, but let's ignore that for now. Really, pretend I didn't mention it.) Suppose further that Thread A runs an infinite loop something along the lines of "sleep for a few seconds, increment integer under lock, repeat". (It's not really that useless, but this should be enough to get the point across.) Meanwhile, Thread B runs a similar loop, but the sleep time is several hours instead of a few seconds. Suppose further that the scheduler is magical and guarantees that there is never any contention. (Preemptive nitpicking: we could just a volatile if that were true. This is just an example. Work with me here.) This assumption is unrealistic, but I'm trying to worry about just one thing at a time.
Now, suppose we care about the average latency between thread A waking up and successfully incrementing its integer. As far as I understand, the JVM would initially bias the lock towards A, and then revoke the bias the first time that thread B woke up.
My question is: would the JVM ever realize that its initial guess was basically correct, and thus re-bias the lock towards Thread A again?