Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.BitSet;
- import java.util.concurrent.Semaphore;
- public class Main {
- private static final int THREADS = 4;
- private static final int N= 60;
- public static Semaphore semaphore = new Semaphore(1);
- public static BitSet set;
- public static int size;
- public static int x;
- public static int maximum;
- public Main(int x) {
- size = x + 1;
- set = new BitSet(size);
- set.flip(2, size);
- maximum = (int) Math.floor(Math.sqrt(size)+1);
- }
- public static void main(String[] args) throws InterruptedException {
- Main bitSetSieveMain = new Main(N);
- Thread [] threadsTab = new Thread[THREADS];
- for(int i=0; i<threadsTab.length; i++) threadsTab[i] = new Thread(new Sito(i));
- long start = System.nanoTime();
- for(int i=0; i<threadsTab.length; i++)
- {
- threadsTab[i].start();
- }
- for(int i=0; i<threadsTab.length; i++)
- {
- threadsTab[i].join();
- }
- long time = System.nanoTime() - start;
- System.out.println(time/10000 + " nano seconds to perform " + set.length() + " numbers " + bitSetSieveMain);
- System.out.println(Main.set.cardinality());
- }
- public String toString() {
- return set.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment