compare and swap vs test and set

test-and-set modifies the contents of a memory location and returns its old value as a single atomic operation. compare-and-swap atomically compares the contents of a memory location to a given value and, only if they are the same, modifies the contents of that memory location to a given new value. The difference marked in bold.

Spring @Async limit number of threads

If you are using Spring’s Java-configuration, your config class needs to implements AsyncConfigurer: @Configuration @EnableAsync public class AppConfig implements AsyncConfigurer { […] @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(2); executor.setMaxPoolSize(5); executor.setQueueCapacity(50); executor.setThreadNamePrefix(“MyExecutor-“); executor.initialize(); return executor; } } See @EnableAsync documentation for more details : http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html

Does Thread.yield() do anything if we have enough processors to service all threads?

Whenever a thread calls the Thread.yield() method, it gives a hint to the thread scheduler that it is ready to pause its execution. The thread scheduler is free to ignore this hint. If any thread executes the yield method, the thread scheduler checks if there is any runnable (waiting to be executed) thread with same … Read more

What is the point of making the singleton instance volatile while using double lock? [duplicate]

The volatile prevents memory writes from being re-ordered, making it impossible for other threads to read uninitialized fields of your singleton through the singleton’s pointer. Consider this situation: thread A discovers that uniqueInstance == null, locks, confirms that it’s still null, and calls singleton’s constructor. The constructor makes a write into member XYZ inside Singleton, … Read more

What is progress and bounded waiting in critical section?

First, let me introduce some terminology. A critical section (CS) is a sequence of instructions that can be executed by at most one process at the same time. When using critical sections, the code can be broken down into the following sections: // Some arbitrary code (such as initialization). EnterCriticalSection(cs); // The code that constitutes … Read more