| 20 | private static final int BLOCK = 64 * 1024 * 1024; |
| 21 | |
| 22 | public static void main(String[] args) throws Exception { |
| 23 | Path tmp = Files.createTempFile("proc-test", ".tmp"); |
| 24 | |
| 25 | // burn some cpu to pass the min cpu % threshold |
| 26 | new Thread(() -> { |
| 27 | while (true) { |
| 28 | long n = random.nextLong(); |
| 29 | if (Long.toString(n).hashCode() == 0) { |
| 30 | System.out.println(n); |
| 31 | } |
| 32 | } |
| 33 | }).start(); |
| 34 | |
| 35 | // write |
| 36 | byte[] payload = new byte[BLOCK]; |
| 37 | random.nextBytes(payload); |
| 38 | |
| 39 | try (FileChannel ch = FileChannel.open(tmp, StandardOpenOption.CREATE, StandardOpenOption.WRITE, |
| 40 | StandardOpenOption.DSYNC)) { |
| 41 | ByteBuffer buf = ByteBuffer.wrap(payload); |
| 42 | while (buf.hasRemaining()) { |
| 43 | ch.write(buf); |
| 44 | } |
| 45 | |
| 46 | ch.force(true); |
| 47 | } |
| 48 | |
| 49 | // read |
| 50 | try (FileChannel f = FileChannel.open(tmp, StandardOpenOption.READ)) { |
| 51 | ByteBuffer b = ByteBuffer.allocate(BLOCK); |
| 52 | f.read(b); |
| 53 | } |
| 54 | |
| 55 | Thread.sleep(20000); |
| 56 | } |
| 57 | } |