title: How to force SELECT blocking on SQL server?
body: <p>I see so much information about avoiding blocks.  My situation is that I WANT blocks.</p>
  
  <p>We have this table with which two separate processes will be communicating with each other.  The processes will run at random times and will use this control table to understand if the other process is busy.  Both processes can't be busy at the same time, hence the control table.</p>
  
  <p>Each job, when run, will check the control table... and based on that data will decide whether it's OK to run, and if OK, will update the control table record.</p>
  
  <p>The issue is that if both processes run at the same moment, it's not clear that they won't do the following undesired actions (in this exact order):</p>
  
  <ol>
  <li>Proc A reads the control table (table says good to go)</li>
  <li>Proc B reads the control table (table says good to go)</li>
  <li>Proc A updates control table (table now says "Proc A is busy")</li>
  <li>Proc B updates control table (table now says "Proc B is busy")</li>
  </ol>
  
  <p>&lt;- In that scenario, both processes think they successfully updated the control table and will start their main flow (which is NOT what we want)</p>
  
  <p>What I want here is for Proc B to be BLOCKED from SELECTING (not just updating) from the control table.  This way, if/when Proc B's select query finally works, it will see the updated 'busy' value, not the value that existed before being changed by Proc A.</p>
  
  <p>We're using SQL Server 2008 R2 I believe. I checked out SERIALIZABLE isolation but it doesn't appear to be strong enough.</p>
  
  <p>For what it's worth we're trying to accomplish this with JDBC... using <code>conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); </code></p>
  
  <p>Which we understand to be the highest level of isolation, but I can still run selects all day from another window.</p>
  
  <p>I'm 100% sure this is nowhere near a unique problem.... does anyone have any suggestion for making this work?</p>