Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Hilo extends Thread{
- private int root;
- private double inicio;
- private double fin;
- private double tiempo;
- private int indice;
- public Hilo(int i) {
- this.indice = i;
- }
- public void run() {
- Random random = new Random();
- inicio = System.currentTimeMillis();
- root = random.nextInt(1,20);
- System.out.println(SumRootN(root));
- fin = System.currentTimeMillis();
- tiempo = fin-inicio;
- System.out.println("Tiempo transcurrido con concurrencia de hilo "+indice+": "+tiempo);
- }
- public static double SumRootN(int root) {
- double result = 0;
- for (int i = 0; i < 10000000; i++) {
- result += Math.exp(Math.log(i) / root);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement