title: How to synchronize a common resource in Java when the application is deployed on multiple instances behind a load balancer
body: <p>How can we synchronize accessing a common resource using synchronization in Java when my java application is deployed on multiple instances behind a load balancer ?</p>
  
  <p>Because, as far as I know, synchronization works only under one JVM. But when we deploy the same Java application on multiple instances to handle the load, then how can we provide a synchronization mechanism?</p>
  
  <p><strong>For example:-</strong> There is a HDFS file to which the java application either appends/edits the contents of that HDFS file. When I deploy my java application on multiple instances, then how can I make sure that only one request from Java application accesses that HDFS file ?</p>