How can I ensure that every thread is working on the same object? We're executing regression on 8 threads parallel. I want to store thread-specific logs in a map, then, after run, do something with the data inside it.
public class Foo {
// map with thread name as a key and queue to keep its logs
public static final Map<String, LinkedList<String>> foofoo = new ConcurrentHashMap<>();
public static void addToQueue(String threadName, String log) {
//some logic here to add log to proper queue
}
}
I want to make sure that whenever any of running threads invokes:
Foo.addToQueue("foo", "fooo");
it is accessing the same map. Thank you for your responses. I'm kind of confused with multi threading, sorry if the question is a bit dumb. Have a nice day! :)
Edit: in the sample up there I've used final keyword when initializing this object, because I know that it blocks objects reference. However does it solve my problem? Is there any better approach?