Practice ยท 3 of 3
Publish safely through a chosen channel
Implement static List<String> publishViaQueue():
1. A worker virtual thread: builds List.of("payload-1", "payload-2"), then puts it on a SynchronousQueue<List<String>>.
2. The main path take()s it and returns the list.
3. Also implement static boolean queueCarriesHappensBefore() returning true โ documenting that BlockingQueue operations establish hb between producer and consumer.
4. Implement static List<String> tornRead() that returns a list published through a PLAIN static field, slept 1ms, then re-read โ this is intentionally NOT guaranteed (the test only checks the method exists and returns some list; the LESSON explains why it is unsafe).
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: JMM drills