equal
deleted
inserted
replaced
35 public class Force { |
35 public class Force { |
36 public static void main(String[] args) throws Exception { |
36 public static void main(String[] args) throws Exception { |
37 Random random = new Random(); |
37 Random random = new Random(); |
38 long filesize = random.nextInt(3*1024*1024); |
38 long filesize = random.nextInt(3*1024*1024); |
39 int cut = random.nextInt((int)filesize); |
39 int cut = random.nextInt((int)filesize); |
40 File file = new File("Blah"); |
40 File file = File.createTempFile("Blah", null); |
41 RandomAccessFile raf = new RandomAccessFile(file, "rw"); |
41 file.deleteOnExit(); |
42 raf.setLength(filesize); |
42 try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) { |
43 FileChannel fc = raf.getChannel(); |
43 raf.setLength(filesize); |
44 MappedByteBuffer buf1 = fc.map( |
44 FileChannel fc = raf.getChannel(); |
45 FileChannel.MapMode.READ_WRITE, cut, filesize-cut); |
45 MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, cut, filesize-cut); |
46 buf1.force(); |
46 mbb.force(); |
47 fc.close(); |
47 } |
48 raf.close(); |
48 |
|
49 // improve chance that mapped buffer will be unmapped |
|
50 System.gc(); |
|
51 Thread.sleep(500); |
49 } |
52 } |
50 } |
53 } |