Tag Info

New answers tagged

2

You are quite close to answering your own question. :) In the Observable/Observer pattern (note the flip), there are three things to bear in mind: Generally, the notification of the change, i.e. 'payload', is in the observable. The observable exists. The observers must be known to the existing observable (or else they have nothing to observe on). By ...


1

Concurrent execution is the generalized form of parallel execution. For example parallel program can also be called concurrent but reverse is not true. Concurrent execution is possible on single processor (multiple threads, managed by scheduler) Parallel execution is not possible on single processor but on multiple processors. (One process per processor) ...


0

Java synchronisation uses a recursive lock for the instance of the synchronised method. It is as if each instance had a recursive lock, and @synchronized would lock that recursive lock (JVM uses a more clever method obviously). Therefore: Any number of threads can use @synchronized for different objects. One thread can use @synchronized for the same ...


4

If you read carefully the documentation of synchronized you will find that it is explicitly stated that once a thread has acquired a lock, it is allowed to re-acquire it as many times as it pleases. According to the Java Language Specification: Section 8.4.3.6. "synchronized Methods" says that the synchronized keyword acquires a monitor. See: ...


2

In Java, synchronized locks are re-entrant. Or in other words if your thread already holds the lock on an object it doesn't have to wait on itself.


1

You can't (realistically) prove thread safety exhaustively for a language like Java, but there are ways to detect some bugs. The official behaviour of your Java program when run on several threads is defined by Chapter 17 of the JLS. The only way to prove that a program is thread safe is by applying all those rules in a theoretical way, which in most ...


1

You have not told us what kind of multi-threading you do, but I presume you do multi-threading of the locking kind, (you use the synchronized keyword of java,) otherwise you probably would not be asking the question. As testing has gained ground in the software engineering discipline during the last decade or so, multi-threading of the locking kind has ...


4

Thread safety means correctness in the face of the exponentially many possible interactions between concurrent processes. Many concurrency-related bugs occur only in a small minority of possible interleavings (but still occur in production because "One in a million is next Tuesday"). Additionally, testing in general is better at finding bugs than assuring ...


2

Demonstrating thread-safety means proving that every possible interleaving of the instructions in two opcode streams leads to the correct result. Therefore, in order to test this property, you must be able to interleave those instructions as desired. In practice, this means that you must have some kind of hook within code that is normally run as a unit. ...



Top 50 recent answers are included