Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.Semaphore;
- public class Processo implements Runnable{
- private int min,max,occ; //Attributi
- private int campo[];
- public Semaphore semaforo;
- /*****************COSTRUTTORI**********************/
- public Processo(int min, int max, int[] campo,int occ) { //Costruttori di default
- this.min = min;
- this.max = max;
- this.campo = campo;
- this.occ = occ;
- this.semaforo = new Semaphore(1);
- }
- @Override
- public String toString() {
- return "Processo{" + "min=" + min + ", max=" + max + ", occ=" + occ + ", campo=" + campo + ", semaforo=" + semaforo + '}';
- }
- public void run(){ //Procedura di ricerca nel sottoinsieme dell'array(da min a max)
- int tot = 0;
- for (int i=this.min;i<this.max;i++){
- if (this.campo[i]==this.occ)
- tot++;
- System.out.println();
- }
- System.out.println("Tot occ = "+tot);
- semaforo.release();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement