Quantcast
Channel: Singleton methods thread safe - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Qing Liu for Singleton methods thread safe

the answer is not thread safe as answered above.This can be test as the code below !public class TestSingleton {public static void main(String[] args) throws Exception { ExecutorService pool =...

View Article



Answer by Tudor for Singleton methods thread safe

The thread-safety of someField.method(); depends on what it's actually doing. If it's modifying state that is shared among multiple threads then it's not thread-safe. If not, it might be thread-safe....

View Article

Answer by Jon Skeet for Singleton methods thread safe

We have no idea whether it's safe or not - we don't know what someField.method() does.I would strongly encourage you to make someField a final field, as if the singleton needs to mutate state then it's...

View Article

Singleton methods thread safe

I have a question Singleton pattern and threads. Implementation is like this.public class Singleton { private static final Singleton instance = new Singleton(); private SomeClass someField; // and...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images