Resolving Java thread visibility and concurrency error using Map compute
问题 I use Java 8. I have an event handler that accepts events with a high rate, (n per second) and I want to flush them out to storage when I get so many of them (in this simplified example 1000) Do I have a visibility error on line 25 myCache.get(event.getKey()).add(event.getBean()); ? Should I synchronize on handleEvent() method? public class myClass extends MySimpleEventHanlder { private Map<String, List<MyBean>> myCache; private ScheduledExecutorService scheduler; public void MyClass() {