code: public static LockRecord lockFile(File f)
  	{
  		LockRecord rec = new LockRecord();
  
  		try
  		{
  			rec.fos = new FileOutputStream(f);
  
  			rec.channel = rec.fos.getChannel();
  			rec.flock = rec.channel.lock();
  		}
  		catch (IOException e)
  		{
  			log.error("[FileHelper] {lockFile} Error while locking " + f + ". Error: " + e.getMessage(), e);
  			if (rec != null)
  			{
  				rec.release();
  			}
  
  			return null;
  		}
  
  		return rec;
  	}
docs: Obtains an exclusive lock on the specified file. By calling this method, the caller guarantees it will call the release()
  method of the LockRecord
  
  @param f
  File The file to lock
  
  @return LockRecord The lock record