package exercises.ex_s1; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; public class Farmer implements Runnable { private String name; private ConcurrentHashMap stalls; private final Random random = new Random(); public Farmer(String name, ConcurrentHashMap stalls) { this.name = name; this.stalls = stalls; } @Override public void run() { while (true) { try { Thread.sleep((long) (1000L + Math.random() * 2000L)); } catch (InterruptedException e) { break; } String key = "box" + random.nextInt(1, 4); int units = random.nextInt(10, 100); stalls.put(key, units); System.out.println(name + " puts " + units + " units of food in " + key); } } }