Skip to content
Advertisement

Tag: thread-safety

Java happens-before relationship?

Consider the following code. Thread A calls run(), then another thread B calls test() and there shouldn’t be any happens-before relationship. I know it is not guaranteed that thread B sees the changes which thread A made. But is it possible that the output of this program is: Answer Yes, it’s possible, because it’s not explicitly forbidden. The read of

Java async MySQL queries

First of all, I don’t have much experience with thread safe programming. I have a MySQL class, and I want to use one instance in multiple threads to prevent blocking code in the main thread. I read about connection pooling but I want to keep it as simple as it is. This is my MySQL class: Is it possible to

Volatile Keyword & the thread local memory [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Why are local variables thread safe in Java

I was reading multi-threading in Java and I come across this Local variables are thread safe in Java. Since then I have been thinking How/Why local variables are thread safe. Can somebody please let me know. Answer When you create a thread it will have its own call stack created. Two threads will have two stacks and one thread never

Thread Safe Singletons in Java

The wikipedia article on Singletons mentions a few thread safe ways to implement the structure in Java. For my questions, let’s consider Singletons that have lengthy initialization procedures and are acccessed by many threads at once. Firstly, is this unmentioned method thread-safe, and if so, what does it synchronize on? Secondly, why is the following implementation thread safe AND lazy

Advertisement