Advertisement
LEANDRONIEVA

ClaseHilo

Sep 28th, 2023
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Hilo extends Thread{
  4.      
  5.     private int root;
  6.     private double inicio;
  7.     private double fin;
  8.     private double tiempo;
  9.     private int indice;
  10.    
  11.     public Hilo(int i) {
  12.         this.indice = i;
  13.     }
  14.     public void run() {
  15.         Random random = new Random();
  16.         inicio = System.currentTimeMillis();
  17.         root = random.nextInt(1,20);
  18.         System.out.println(SumRootN(root));        
  19.        
  20.         fin = System.currentTimeMillis();
  21.         tiempo = fin-inicio;
  22.        
  23.         System.out.println("Tiempo transcurrido con concurrencia de hilo "+indice+": "+tiempo);    
  24.     }
  25.    
  26.     public static double SumRootN(int root) {
  27.         double result = 0;
  28.         for (int i = 0; i < 10000000; i++) {
  29.             result += Math.exp(Math.log(i) / root);
  30.         }
  31.         return result;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement