Package java.nio.channels

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


      File sf = new File(Global.provisionalPath);//����ʱ�ļ��д���һ����ʱ�ļ�����ס����ļ�������֤Ӧ�ó���ֻ��һ��ʵ��������
      sf.deleteOnExit();
      sf.createNewFile();
      raf = new RandomAccessFile(sf,"rw");
      channel = raf.getChannel();
      lock = channel.tryLock();
     
      if(lock == null){//lockΪ��ʱ����û�еõ��������Ѿ���һ��ʵ�������У���ʾ�������в��˳���
        BaseFrame.alert("ע�⣺JAVA����Ӧ�÷����������Ѿ����У�");
        System.exit(0);
      }     
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

        final long dropDeadTime = System.currentTimeMillis() + waitMS;
        final File file = new File(lockTempDir, c.getName() + ".lock");
        randomAccessFile = new RandomAccessFile(file, "rw");
        final FileChannel fileChannel = randomAccessFile.getChannel();
        while (System.currentTimeMillis() < dropDeadTime) {
          fileLock = fileChannel.tryLock();
          if (fileLock != null) {
            break;
          }
          Thread.sleep(250); // 4 attempts/sec
        }
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

                /*
                 * 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

                /*
                 * 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

                /*
                 * 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

                    // We got an IOException while trying to open the file.
                    // Try the next file.
                    continue;
                }
                try {
                    FileLock fl = fc.tryLock();
                    if (fl == null) {
                        // We failed to get the lock.  Try next file.
                        continue;
                    }
                    // We got the lock OK.
View Full Code Here

                    FileLock markerLock = null;
                    try {
                        try {
                            markerFile = new RandomAccessFile(marker, "rw");
                            markerChannel = markerFile.getChannel();
                            markerLock = markerChannel.tryLock();
                            inUse = markerLock == null;
                            if (inUse) {
                                LOGGER.config("EP cleanup: the marker " + marker + " is locked in another JVM");
                            } else {
                                LOGGER.config("EP cleanup: " + workDir + " was probably not deleted due to "
View Full Code Here

                if (file.getParentFile().exists() || file.getParentFile().mkdirs()) {
                    RandomAccessFile raf =
                        new RandomAccessFile(file, "rw");           
                    FileChannel channel = raf.getChannel();
                    try {
                        FileLock l = channel.tryLock();
                        if (l != null) {
                            synchronized (this) {
                                locks.put(file, l);
                            }
                            return true;
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.