Concurrency – Two threads querying multiple databases from different servers and compare each record synchronously

I want to have two threads querying (JDBC) two tables (from different servers/databases but related) for an ordered output then compare them or apply some logic record by record. The table size can be …

Can a thread lose control after calling a method but before the first instruction of the method?

I need to record the exact order in which a method is called by various threads in Java. I’m supposed to use an object timeProvider which returns non-decreasing long integers. The solution I have come …

Custom hashCode implementation for ConcurrentSkipListMap doen’t work as expected

The idea is to allow ConcurrentSkipListMap to store only one ApprovalRequest which has unique customerId and its state is PENDING. I supplied overridden hashCode and equals implementations. Moreover, …

how to understand this interface Executor example in Java API docs [closed]

Can anyone help to explain this piece of code in details? class SerialExecutor implements Executor { final Queue tasks = new ArrayDeque(); final Executor …

ConcurrentModificationException when iterate through ImmutableMap.copyof()

Currently, I have a problem when I frequently iterating through a HashMap (1-time per second) I add new element to the map on the main thread and iterate the map on the other thread I return an …

How does java IoC framework ensure thread safety?

Recently I have read a great tutorial of Java Memory Model. It says JVM only guarantees the visibility of final field if no synchronization used. Then it occurs to me that when we use some IoC …

What is a usecase for Java AtomicReference#getAndSet?

What is a usecase for Java AtomicReference#getAndSet? In other words, is it correct assumption, that if the only method from AtomicReference that I use in my code is AtomicReference#getAndSet, then I …

ForkJoinFramwork, call compute() directly without explicit ForkJoinPool/ExecutorService

Q: What happens when the compute() method, in a class “X” that extends RecursiveAction/Task, is directly called? Without calling a ForkJoinPool explicitly like the following: ForkJoinPool …

java – synchronization and volatile variable

I’ve read from this article that: …Synchronized blocks also guarantee that all variables accessed inside the synchronized block will be read in from main memory, and when the thread exits the …

Java happens-before relationship?

Consider the following code. public class Test { private boolean running = false; public void run() { running = true; } public void test() { boolean running1 = …