title: Avoid JVM stop-the-world in critical section of code
body: <p>I'm trying to solve a problem where I want to ensure mutual exclusiveness among multiple processes running on different machines. I want to ensure that there is always one and only one process executing the critical section. To achieve that, I maintain a lock in a database which expires with time. It expires to avoid starvation.</p>
  
  <p>Now, given that JVM can go into stop-the-world (STW) state anytime, it means, if a process is in STW long enough, another process can enter the critical section. I want to know -</p>
  
  <blockquote>
    <ol>
    <li>If there is a way a thread can be notified/killed before JVM starts STW? </li>
    <li>If there is a way I can configure JVM not do STW while a thread is in the critical section of the code? </li>
    <li>If there is a way an application could specify the 'safe points' to JVM? </li>
    <li>If there is a way I can configure JVM to crash instead of going into STW?</li>
    </ol>
  </blockquote>
  
  <p>PS: I understand that I can have a insanely large timeout on the locks I'm creating based on the JVM configuration. It'll ensure that JVM STW will finish before the lock expiry. But that is not future-proof and is not the point of discussion. I'm also not looking for the ways to reduce the number of SWT or duration of STW as they do not have guarantees I'm looking.</p>