How to write PI calculation program in Java using multi-thread?
<p>I need to create a program that can calculate approximation to the constant PI, using Java multi-thread.</p>

<p>I'm intent to use Gregory-Leibniz Series to calculate the result for PI / 4, and then multiply by 4 to get the PI approximation.</p>

<p><a href="https://i.stack.imgur.com/PhliG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PhliG.png" alt="enter image description here"></a></p>

<p>But I have some concern about the program:</p>

<ol>
<li>How can I seperate the calculation process so that I can implement a multi-thread processing for the program? Because the formula is for the total sum, I don't know how to split them into parts and then in the end I will collect them all.</li>
<li>I'm thinking about the fact that the program will execute the formula to infinite so user will need to provide some means of configuring the execution in order to determine when it should stop and return a result. Is it possible and how can I do that?</li>
</ol>

<p>This is so far the most I can do by now.</p>

<pre><code>public class PICalculate {

    public static void main(String[] args) {
        System.out.println(calculatePI(5000000) * 4);
    }

    static double calculatePI(int n) {
        double result = 0.0;
        if (n &lt; 0) {
            return 0.0;
        }
        for (int i = 0; i &lt;= n; i++) {
            result += Math.pow(-1, i) / ((2 * i) + 1);
        }
        return result;
    }
}
</code></pre>