1. 程式人生 > >並行流與序列流

並行流與序列流

parallel() 與sequential()
底層是fork join框架

@Test
	public void test3(){
		long start = System.currentTimeMillis();
		
		Long sum = LongStream.rangeClosed(0L, 10000000000L)
							 .parallel()
							 .sum();
		
		System.out.println(sum);
		
		long end = System.currentTimeMillis();
		
		System.out.println("耗費的時間為: " + (end - start)); //2061-2053-2086-18926
	}