| 11 | static final int LENGTH = 0x8FFFFFF; // 128 MB |
| 12 | static FileChannel fc; |
| 13 | public static void |
| 14 | main(String[] args) throws Exception { |
| 15 | fc = new RandomAccessFile("test.dat", "rw") |
| 16 | .getChannel(); |
| 17 | MappedByteBuffer out = fc.map( |
| 18 | FileChannel.MapMode.READ_WRITE, 0, LENGTH); |
| 19 | for(int i = 0; i < LENGTH; i++) |
| 20 | out.put((byte)'x'); |
| 21 | new LockAndModify(out, 0, 0 + LENGTH/3); |
| 22 | new LockAndModify( |
| 23 | out, LENGTH/2, LENGTH/2 + LENGTH/4); |
| 24 | } |
| 25 | private static class LockAndModify extends Thread { |
| 26 | private ByteBuffer buff; |
| 27 | private int start, end; |