Advertisement
Guest User

ca;łka

a guest
Nov 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class MyThread extends Thread {
  2.  
  3. private int id;
  4. private double x;
  5. public static double sum;
  6. public static int n;
  7. private static Object mutex = new Object();
  8.  
  9. MyThread(int id) {
  10. this.id = id;
  11. }
  12.  
  13. public void run() {
  14.  
  15. double ss=0;
  16. for(int i = id;i<n;i += 4) {
  17.  
  18. x = (double) i / n;
  19.  
  20. double f = 4/(1+x*x);
  21.  
  22. double p = f /(double)n;
  23.  
  24. ss =ss + p;
  25.  
  26. }
  27.  
  28. synchronized (mutex) {
  29. sum = sum + ss;
  30. }
  31.  
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement