Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
public class Productor extends Thread{ private ArrayList
lista; private int num; private Random random=new Random(); public Productor(ArrayList
lista,int num) { this.lista=lista; this.num=num; } public void run() { int tiempoInicial=1000; int tiempoFinal=1500; while(true) { try { int elemento=random.nextInt(1000)+1; int tiempoRetardo=random.nextInt((tiempoFinal-tiempoInicial)+1)+tiempoInicial; Thread.sleep(tiempoRetardo); synchronized(lista) { lista.add(elemento); //lista.notify(); // Notificar a un consumidor que hay un nuevo elemento disponible System.out.println("Productor "+this.num+" produjo: "+elemento); lista.notifyAll(); // Notificar a todos los consumidores que hay un nuevo elemento disponible } } catch (InterruptedException e) { e.printStackTrace(); } } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)