Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyThread extends Thread {
- private int id;
- private double x;
- public static double sum;
- public static int n;
- private static Object mutex = new Object();
- MyThread(int id) {
- this.id = id;
- }
- public void run() {
- double ss=0;
- for(int i = id;i<n;i += 4) {
- x = (double) i / n;
- double f = 4/(1+x*x);
- double p = f /(double)n;
- ss =ss + p;
- }
- synchronized (mutex) {
- sum = sum + ss;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement