Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.concurrent.Semaphore;
  2.  
  3. public class Processo implements Runnable{
  4.    
  5.     private int min,max,occ;                                                //Attributi
  6.     private int campo[];
  7.     public Semaphore semaforo;
  8.    
  9.     /*****************COSTRUTTORI**********************/
  10.     public Processo(int min, int max, int[] campo,int occ) {                //Costruttori di default
  11.         this.min = min;
  12.         this.max = max;
  13.         this.campo = campo;
  14.         this.occ = occ;
  15.         this.semaforo = new Semaphore(1);
  16.     }
  17.  
  18.     @Override
  19.     public String toString() {
  20.         return "Processo{" + "min=" + min + ", max=" + max + ", occ=" + occ + ", campo=" + campo + ", semaforo=" + semaforo + '}';
  21.     }
  22.    
  23.    
  24.    
  25.     public void run(){                                                      //Procedura di ricerca nel sottoinsieme dell'array(da min a max)
  26.         int tot = 0;  
  27.        
  28.         for (int i=this.min;i<this.max;i++){
  29.             if (this.campo[i]==this.occ)
  30.             tot++;
  31.             System.out.println();
  32.         }
  33.         System.out.println("Tot occ = "+tot);
  34.        
  35.         semaforo.release();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement