Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 899 Bytes

README.md

File metadata and controls

34 lines (28 loc) · 899 Bytes

Parallel Tool

A simple and optimized tool to parallel tasks.

Use this tool like Collection.parallelStream in Java 8;

For now it supports to process List.

  • Process without Result return
List<Integer> list = Lists.newArrayList(65, 66, 67, 68, 69, 70);
ListParallel.parallel(list, new VoidProcessor<Integer>() {
	@Override
	public void process(Integer e) {
		System.out.println(e + 1);
	}
});
  • Process with Result return
List<Character> result = ListParallel.parallelWithCallback(list, new CallbackProcessor<Integer, Character>() {
	@Override
	public Character process(Integer e) {
		return (char) e.intValue();
	}
});
  • Thread Number Specify
    • When execute CPU bound task, you should use Runtime.getRuntime().availableProcessors() + 1 as thread number.
ListParallel.parallel(list, voidProcessor, Runtime.getRuntime().availableProcessors() + 1);