Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Date d1 = new Date();
- CounterClass c1 = new CounterClass(10000000, 40000000);
- while (true){
- if(!c1.getTh().isAlive()){
- System.out.println("Длина списка: " + c1.getList().size());
- Date d2 = new Date();
- long time = d2.getTime() - d1.getTime();
- System.out.println("Время выполнения: " + time + " мс"); //у меня ~700 мс
- break;
- }
- }
- }
- }
- public class CounterClass implements Runnable {
- private int beginIndex;
- private int endIndex;
- private ArrayList<Integer> list = new ArrayList<>();
- private Thread th;
- public CounterClass(int beginIndex, int endIndex) {
- this.beginIndex = beginIndex;
- this.endIndex = endIndex;
- th = new Thread(this);
- th.start();
- }
- @Override
- public void run() {
- for(int i = beginIndex; i <= endIndex; i++){
- if(i % 11 == 0 || i % 13 == 0 || i % 17 == 0) list.add(i);
- }
- }
- public Thread getTh() {
- return th;
- }
- public ArrayList<Integer> getList() {
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement