FileDocCategorySizeDatePackage
LockOverlap.javaAPI DocExample991Mon May 20 03:03:42 BST 2002com.ronsoft.books.nio.channels

LockOverlap

public class LockOverlap extends Object
Test overlapping locks on different file channels.
author
Ron Hitchens (ron@ronsoft.com)

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		if (argv.length == 0) {
			System.out.println ("Usage: filename");
			return;
		}

		String filename = argv [0];

		RandomAccessFile raf1 = new RandomAccessFile (filename, "rw");
		FileChannel fc1 = raf1.getChannel();

		RandomAccessFile raf2 = new RandomAccessFile (filename, "rw");
		FileChannel fc2 = raf2.getChannel();

		System.out.println ("Grabbing first lock");
		FileLock lock1 = fc1.lock (0L, Integer.MAX_VALUE, false);

		System.out.println ("Grabbing second lock");
		FileLock lock2 = fc2.lock (5, 10, false);

		System.out.println ("Exiting");