+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
828c852
master
1import java .util .concurrent .*; 2class Fibonacci2 implements Callable <Integer > { 3public static ExecutorService threadPool =Executors .newCachedThreadPool (); 4int n ; 5public Fibonacci2 (int n ) { 6this .n =n ; 7 } 8public Integer call () { 9try { 10if ((n ==0 )||(n ==1 ))return 1 ; 11else { 12Future <Integer >f1 =threadPool .submit (new Fibonacci2 (n -1 )); 13Future <Integer >f2 =threadPool .submit (new Fibonacci2 (n -2 )); 14return f1 .get () +f2 .get (); 15 } 16 }catch (Exception e ) {System .err .println (e );return 1 ;} 17 } 18 19public static void main (String []args ) { 20try { 21ExecutorService es =Executors .newSingleThreadExecutor (); 22Fibonacci2 f =new Fibonacci2 (Integer .parseInt (args [0 ])); 23Future <Integer >f1 =es .submit (f ); 24System .out .println ("Answer is " +f1 .get ()); 25es .shutdown (); 26f .threadPool .shutdown (); 27 }catch (Exception e ) {System .err .println (e ); } 28 } 29}