September 2019
Intermediate to advanced
816 pages
18h 47m
English
Let's assume that we have the following Order class:
public class Order { private final int customerId; public Order(int customerId) { this.customerId = customerId; } // getter and toString() omitted for brevity}
And, we write CustomerOrder as follows:
public class CustomerOrder implements Runnable { private static final Logger logger = Logger.getLogger(CustomerOrder.class.getName()); private static final Random rnd = new Random(); private static final ThreadLocal<Order> customerOrder = new ThreadLocal<>(); private final int customerId; public CustomerOrder(int customerId) { this.customerId = customerId; } @Override public void run() { logger.info(() -> "Given customer id: " + customerId + " | " + customerOrder.get() ...