It is not possible to allocate a certain percentage of CPU / memory time for a given thread. You can lower the priority of a stream so that it does not saturate all resources:
int oldPriority = Thread.currentThread().getPriority();
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
Thread.currentThread().setPriority(oldPriority);
, , , , ExecutorService . , 50% . , singleton :
int threads = Runtime.getRuntime().availableProcessors() / 2;
ExecutorService service = Executors.newFixedThreadPool(threads);
- Callable, , :
Callable<Result> callable = new DocumentProcessorCallable<Object>(doc);
Result result = service.submit(callable).get();
, Runnable, service.execute(runnable). . ExecutorService .