Logo Search packages:      
Sourcecode: fetchexc version File versions  Download package

FileLock SendMbox::lockFile ( FileChannel  lockChannel,
boolean  spinLockOnly 
) throws IOException [inline, private]

Tries to lock the file channel provided. We try a spin lock first and if that fails, we optionally fall back on a blocking lock.

Returns:
a FileLock for the file or null if no lock could be obtained.

Definition at line 172 of file SendMbox.java.

                                     {
            final int LOCK_COUNT = 5;
            FileLock lock = null;

            for (int i = 0; i < LOCK_COUNT; i++) {
                  lock = lockChannel.tryLock();
                  if (lock != null) {
                        // Ya! We have a lock on this file
                        break;
                  }

            }

            if (lock == null && !spinLockOnly) {
                  // Spin locks failed, try a blocking lock.
                  // System.out.println("File locked by another process, waiting until
                  // it is available to lock it ourselves");
                  lock = lockChannel.lock();
            }

            // May be null if we could not get a spin lock and were told not
            // to wait (spinLockOnly = false) .
            return lock;

      }

Generated by  Doxygen 1.6.0   Back to index