Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.Lock.tryLock()


      try {
        byte []blockBuffer = block.getBuffer();
        int freeOffset = -1;

        Lock lock = block.getWriteLock();
        lock.tryLock(_blockLockTimeout, TimeUnit.MILLISECONDS);

        try {
          for (int i = 0; i < MINI_FRAG_PER_BLOCK; i++) {
            int offset = i / 8 + MINI_FRAG_ALLOC_OFFSET;
            int mask = 1 << (i % 8);
View Full Code Here


  {
    Block block = readBlock(fragmentAddress);

    try {
      Lock lock = block.getWriteLock();
      lock.tryLock(_blockLockTimeout, TimeUnit.MILLISECONDS);

      try {
        int fragIndex = (int) (fragmentAddress & BLOCK_OFFSET_MASK);
        int offset = fragIndex / 8 + MINI_FRAG_ALLOC_OFFSET;
        int mask = 1 << (fragIndex % 8);
View Full Code Here

    Block block = readBlock(addressToBlockId(fragmentAddress));

    try {
      Lock lock = block.getWriteLock();
      lock.tryLock(_blockLockTimeout, TimeUnit.MILLISECONDS);

      try {
        int blockOffset = getMiniFragmentOffset(fragmentAddress);

        byte []blockBuffer = block.getBuffer();
View Full Code Here

    Block block = readBlock(addressToBlockId(fragmentAddress));

    try {
      Lock lock = block.getWriteLock();
      lock.tryLock(_blockLockTimeout, TimeUnit.MILLISECONDS);

      try {
        int blockOffset = getMiniFragmentOffset(fragmentAddress);

        byte []blockBuffer = block.getBuffer();
View Full Code Here

  private int allocateRow(Block block, DbTransaction xa)
    throws IOException, SQLException, InterruptedException
  {
    Lock blockLock = block.getWriteLock();

    blockLock.tryLock(xa.getTimeout(), TimeUnit.MILLISECONDS);
    try {
      block.read();

      byte []buffer = block.getBuffer();
View Full Code Here

   public void acquireProcessingLock(boolean exclusive, long timeout, TimeUnit timeUnit) throws TimeoutException {
      while (true) {
         try {
            Lock lock = exclusive ? processingLock.writeLock() : processingLock.readLock();
            if (!lock.tryLock(timeout, timeUnit))
               throw new TimeoutException("Could not obtain " + (exclusive ? "exclusive" : "shared") + " processing lock");
            break;
         } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
         }
View Full Code Here

    @Override
    public Object call() throws Exception {
      String lockKey = jobData.getTargetItemKey().getUrl();
      Lock lock = lockSystem.getLock(lockKey);

      boolean locked = lock.tryLock();

      if (!locked) {
        log.debug("Cannot get lock to run job: " + lockKey);

        long retry = System.currentTimeMillis() + 1000;
View Full Code Here

            // wait indefinitely for a lock
            currLock.lock();
            lockAcquired = true;
        } else if (accessTimeout.getTime() == 0) {
            // concurrent calls are not allowed, lock only once
        lockAcquired = currLock.tryLock();
      } else {
        // try to get a lock within the specified period.
        try {
        lockAcquired = currLock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
      } catch (InterruptedException e) {
View Full Code Here

            // concurrent calls are not allowed, lock only once
        lockAcquired = currLock.tryLock();
      } else {
        // try to get a lock within the specified period.
        try {
        lockAcquired = currLock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
      } catch (InterruptedException e) {
        throw new ApplicationException("Unable to get lock.", e);
      }
      }
        // Did we acquire the lock to the current execution?
View Full Code Here

        } else {
            lock = instance.lock.writeLock();
        }

        try {
            if (!lock.tryLock(wait, unit)){
                throw new ConcurrentAccessTimeoutException();
            }
        } catch (InterruptedException e) {
            throw (ConcurrentAccessTimeoutException) new ConcurrentAccessTimeoutException().initCause(e);
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.