packageproducerConsumer;publicclassProducerimplementsRunnable{privatefinalStringid;privatefinalQueuequeue;publicProducer(Stringid,Queueq){this.id=id;queue=q;}publicvoidrun(){while(true){Stringmessage=produce();System.out.println("Prod. "+id+": inserisco "+message);queue.put(message);try{Thread.sleep(1000);}catch(InterruptedExceptione){e.printStackTrace();}}}privateintcounter=0;publicStringproduce(){counter++;return"Messaggio da "+id+" n. "+counter;}}