Commit 9a158211 authored by Gabriele Civitarese's avatar Gabriele Civitarese

all the code under src folder

parent 3616ae49
package join;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
...@@ -22,6 +24,7 @@ public class Main { ...@@ -22,6 +24,7 @@ public class Main {
for (Thread t : threads) { for (Thread t : threads) {
t.join(); t.join();
} }
System.out.println("...All thread finished!"); System.out.println("...All thread finished!");
} }
......
package join;
import java.util.Random; import java.util.Random;
public class MyThread extends Thread { public class MyThread extends Thread {
......
package producerConsumer;
public class Consumer implements Runnable { public class Consumer implements Runnable {
private final Queue queue; private final Queue queue;
......
package producerConsumer;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Queue q = new Queue(); Queue q = new Queue();
......
package producerConsumer;
public class Producer implements Runnable { public class Producer implements Runnable {
private final String id; private final String id;
......
package producerConsumer;
import java.util.ArrayList; import java.util.ArrayList;
public class Queue { public class Queue {
......
package producerConsumerUnsynced;
public class Consumer implements Runnable { public class Consumer implements Runnable {
private final Queue queue; private final Queue queue;
......
package producerConsumerUnsynced;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Queue q = new Queue(); Queue q = new Queue();
......
package producerConsumerUnsynced;
public class Producer implements Runnable { public class Producer implements Runnable {
private final String id; private final String id;
......
package producerConsumerUnsynced;
import java.util.ArrayList; import java.util.ArrayList;
//Esempio di coda condivisa che non usa wait e notify //Esempio di coda condivisa che non usa wait e notify
......
package semaphore;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
//Utilizzo di un semaforo "fatto a "
public class Main { public class Main {
public static void main(String arg[]) throws Exception { public static void main(String arg[]) throws Exception {
Random r = new Random(); Random r = new Random();
......
package semaphore;
import java.util.Random; import java.util.Random;
public class MyThread extends Thread { public class MyThread extends Thread {
......
//Classe che implementa tramite wait e notify un Semaforo. package semaphore;//Classe che implementa tramite wait e notify un Semaforo.
//Se non vi ricordate cosa sia un semaforo, google is your best friend. //Se non vi ricordate cosa sia un semaforo, google is your best friend.
public class Semaphore extends Thread { public class Semaphore {
private int maxNumber; //numero massimo di thread private int maxNumber; //numero massimo di thread
private int threadsIn; //conteggio dei thread nell'area critica private int threadsIn; //conteggio dei thread nell'area critica
......
package semaphoreAPI;
import java.util.Random; import java.util.Random;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
......
package semaphoreAPI;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment