Package java.nio.channels

Examples of java.nio.channels.FileChannel.tryLock()


            }
            RandomAccessFile raf = new RandomAccessFile(lockfile, "rw");
            try {
                FileChannel channel = raf.getChannel();
                try {
                    FileLock lock = channel.tryLock();
                  if (lock == null) {
                        throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", ignore and retry later, maybe multi java process use the file, please config: dubbo.regitry.file=xxx.properties");
                    }
                  // 保存
                    try {
View Full Code Here


      // Get the channel
      FileChannel channel = new RandomAccessFile(f, "rw").getChannel();
      FileLock lockOrNull = null;
      // Try the lock
      for (int i = 0; i < 1000; ++i) {
        lockOrNull = channel.tryLock();
        if (lockOrNull == null || !lockOrNull.isValid()) {
          try { Thread.sleep(1000); } catch (InterruptedException e) { log(e); }
          if (i % 60 == 59) { warn("FileBackedCache", "Lock still busy after " + ((i+1)/60) + " minutes"); }
          //noinspection UnnecessaryContinue
          continue;
View Full Code Here

                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                FileLock lock = null;
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

                    }
                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    LOG.trace("Acquired exclusive read lock: {} to file: {}", lock, target);
View Full Code Here

                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                FileLock lock = null;
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

        FileLock lock = null;
        ByteBuffer bb = null;
        try {
            channel = fos.getChannel();
            if (channel != null) {
                lock = channel.tryLock();
            }
            bb = getTempByteBuffer();
        } catch (Throwable t) {
        }
        if (lock == null || bb == null || !bb.hasArray()) {
View Full Code Here

     
      try {
              FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
         
              try {
                  channel.tryLock();
              } catch (OverlappingFileLockException e) {
              }
          } catch (Exception e) {
          }
     
View Full Code Here

     
      try {
              FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
         
              try {
                  channel.tryLock();
              } catch (OverlappingFileLockException e) {
              }
          } catch (Exception e) {
          }
     
View Full Code Here

                /*
                 * if lock is unsupported and IOException thrown, just let the
                 * IOException throws out and exit otherwise it will go into an
                 * undead cycle
                 */
                lock = channel.tryLock();
                if (null == lock) {
                    try {
                        fileStream.close();
                    } catch (Exception e) {
                        // ignore
View Full Code Here

            {
                _storeRAF = new RandomAccessFile(_storeFile, "rw");
                FileChannel fileChannel = _storeRAF.getChannel();
                try
                {
                    _storeLock = fileChannel.tryLock();
                }
                catch (OverlappingFileLockException e)
                {
                    _storeLock = null;
                }
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.