Skip to content
Advertisement

Tag: synchronized

Java Synchronized on the same file, but not different

I have this static class: that have lots of methods and this one above is one of these. what I would like to do is that if two callers write to the same file, the writing should be done in mutual exclusion. But when callers write to different files, this doesn’t happen (they don’t write in mutual exclusion). This versione

is synchronized needed in getValue() ? & volatile needed?

I’ve a class in multithreading application: Answer The keyword volatile gives you the visibility aspects and without that you may read some stale value. A volatile read adds a memory barrier such that the compiler, hardware or the JVM can’t reorder the memory operations in ways that would violate the visibility guarantees provided by the memory model. According to the

Implementing a resource read/write lock in Java

I’m trying to implement a simple read/write lock for a resource accessed concurrently by multiple threads. The workers randomly try reading or writing to a shared object. When a read lock is set, workers should not be able to write until the lock is released. When a write lock is set, read and write are not permitted. Although my implementation

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

Advertisement