Guest User

Untitled

a guest
Oct 23rd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.BitSet;
  2. import java.util.concurrent.Semaphore;
  3.  
  4. public class Main {
  5.  
  6.      private static final int THREADS = 1;
  7.      public static Semaphore semaphore = new Semaphore(1);
  8.      
  9.        
  10.      public static BitSet set;
  11.      public static int size;
  12.      
  13.            
  14.         public Main(int x) {
  15.             size = x + 1;
  16.             set = new BitSet(size);
  17.             set.flip(2, size);
  18.            
  19.         }
  20.    
  21.     public static void main(String[] args) throws InterruptedException {
  22.          
  23.                 Main bitSetSieveMain = new Main(60);
  24.                 Thread [] threadsTab = new Thread[THREADS];
  25.                
  26.                 for(int i=0; i<threadsTab.length; i++) threadsTab[i] = new Thread(new Sito(i));
  27.                
  28.                 long start = System.nanoTime();
  29.                
  30.                
  31.                 for(int i=0; i<threadsTab.length; i++)
  32.                 {
  33.                     threadsTab[i].start();
  34.  
  35.                 }
  36.                 for(int i=0; i<threadsTab.length; i++)
  37.                 {
  38.                     threadsTab[i].join();
  39.                 }
  40.  
  41.                 long time = System.nanoTime() - start;
  42.                
  43.                 System.out.println(time + " nano seconds to perform " + set.length() + " numbers " + bitSetSieveMain);
  44.                
  45.            
  46.  
  47.     }
  48.    
  49.    
  50.    
  51.    
  52.  
  53.     public String toString() {
  54.         return set.toString();
  55.     }
  56.    
  57.    
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment