Untitled
unknown
plain_text
4 years ago
1.1 kB
13
Indexable
package com.company;
import java.util.ArrayList;
import java.util.List;
class Loop1{
public static void main(String[] args) throws InterruptedException {
// write your code here
long start = System.currentTimeMillis();
List<Thread> threads = new ArrayList<>();
int thread = 40, loop = 100;
for (int i = 1; i <= thread; ++i) {
Thread t = new Loop2("Thread " + i, loop);
t.start();
threads.add(t);
}
for (Thread t : threads) {
t.join();
}
long stop = System.currentTimeMillis();
System.out.println("Total Thread : " + thread + " | Looping : " + loop);
System.out.println("Total : " + (stop-start) + " Milisecond");
}
}
class Loop2 extends Thread {
private String myName;
private int looping;
public Loop2 (String name, int loop) {
myName = name;
looping = loop;
}
public void run() {
for(int i = 1; i <= looping; i++) {
System.out.println(myName + " (" + i + ")");
}
}
}Editor is loading...