Finding prime numbers by threads in java(1)
In this article i would like to mention about how to find prime numbers with threads asynchronously but first i’m gonna quick recap an easy library whic is called PCDP
In PCDP there are two main operations you should now about: PCDP.finish() and PCDP.async()
basically when we call PCDP.async(()=>{// some calculations here!!}) as described, the program will create a new thread and starts to execute the code which is given as parameter.
PCDP.finish(()=>{}) is make sure that any PCDP.async(..) operation is finished which is defined inside the parameter function. so if we say that;
S1 and S2 runs simultaneously and doesn’t wait one or another.
In this example there is a main thread by default. and with async call, we create another thread and start to execute S1; operations as the same time main thread executes the S2 operations and because we didn’t define the finish operation main thread going to return after the execution of s2 while s1 is continuing(may or may not).
S1 and S2 runs simultaneously and only after completion of these (we make sure that all created threads are finished inside the finish(..) call) S3 runs.