Not familiar with multithreading. It is necessary to calculate the integral using the sum on java. The user selects the accuracy and number of threads. Sets the number -n into which the segment (a, b) is divided.

I think there will be some kind of Controller class that will manage threads and distribute tasks to them. And the terms of this entire amount will gradually increase the total variable amount in the Controller itself, and already counted indexes will be stored somewhere in the list. At the end simply withdraw the amount. I do not know how to implement it on java.

Here's how to do it in one thread?

private double InFunction(double x){ return Math.sin(x); } public double calcIntegral(double a, double b, int n) { double result, h; int i; h = (ba)/n; //Шаг сетки result = 0; for(i=1; i <= n; i++) { result += InFunction(a + h * i - h/2); //Вычисляем в средней точке и добавляем в сумму } result *= h; return result; } 

I have already done it in two ways: using notify, wait and the second way - using join

    1 answer 1

    I do not know, as in Java, but on .NET manual flow control is considered a low-level moveton. Instead, write like this:

     var h = (b - a)/n; return ParallelEnumerable.Range(1, n).Sum(i => InFunction(a + h * i - h/2)) * h;