So your problem has two aspects:
- Calculate limitation
- IO bound
Reading and writing to a file are tied to IO. Async IO is the best for IO related tasks. Java has an AsynchronousFileChannel that allows you to read and write files without worrying about thread pools, where continuation is achieved through completion handlers. Full example.
AsynchronousFileChannel ch = AsynchronousFileChannel.open(path); final ByteBuffer buf = ByteBuffer.allocate(1024); ch.read(buf, 0, 0, new CompletionHandler() { public void completed(Integer result, Integer length){ .. } public void failed(Throwable exc, Integer length) { .. } } );
And you do the same for recording, you just write to the channel
ch.write(...
There is no file parsing, that is, tasks related to computing, and you need your processor cores to be hot for this, you can assign a thread pool to the number of cores that you have.
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
Now remember that you need to test your code, and testing parallel code is difficult. If you canβt confirm your case, donβt do it.
source share