Top "Thread-safety" questions

A piece of code is thread-safe if it only manipulates data structures in a way that allows consistent execution of this code by multiple threads.

Android threading and database locking

We are using AsyncTasks to access database tables and cursors. Unfortunately we are seeing occasional exceptions regarding the database being …

android sqlite locking thread-safety android-asynctask
How to ensure thread safety of utility static method?

Is there any general way or rules exits by which we can ensure the thread safety of static methods specifically …

java oop thread-safety static-methods utility
Is a HashMap thread-safe for different keys?

If I have two multiple threads accessing a HashMap, but guarantee that they'll never be accessing the same key at …

java multithreading thread-safety hashmap
How to create a task (TPL) running a STA thread?

Using Thread is pretty straightforward Thread thread = new Thread(MethodWhichRequiresSTA); thread.SetApartmentState(ApartmentState.STA); How to accomplish the same using …

c# wpf multithreading thread-safety task-parallel-library
Is it OK to use Gson instance as a static field in a model bean (reuse)?

Here's the model I implemented: public class LoginSession { private static final Gson gson = new Gson(); private String id; private String …

java static thread-safety gson
Is LinkedList thread-safe when I'm accessing it with offer and poll exclusively?

I have a linked list samples: protected LinkedList<RawDataset> samples = new LinkedList<RawDataset>(); I'm appending elements …

java multithreading list thread-safety linked-list
Thread safe logging class implementation

Would the following be the correct way to implement a fairly straightforward thread-safe logging class? I know that I never …

c# multithreading logging thread-safety
Is std::vector or boost::vector thread safe?

I have multiple threads simultaneously calling push_back() on a shared object of std::vector. Is std::vector thread safe? …

c++ boost stl thread-safety std
How to implement thread-safe lazy initialization?

What are some recommended approaches to achieving thread-safe lazy initialization? For instance, // Not thread-safe public Foo getInstance(){ if(INSTANCE == null){ …

java thread-safety lazy-initialization
Is Hibernate's session thread safe?

I need to know, whether the Hibernate's session is thread safe or not. But obvious a new session is attached …

java hibernate session thread-safety hibernate-session