Java - Multithreading



Troubleshooting Java 

http://www.oracle.com/technetwork/java/javase/hangloop-140257.html

http://www.javaworld.com/article/2078848/java-concurrency/java-101-the-next-generation-java-concurrency-without-the-pain-part-2.html?page=3
Producer - Consumer

3 possible implementations
1. wait / notify
2. Semaphores
3. CAS - Lock free - Using Atomic variables

Again

  1. wait() / notify()  - synchronisation / Lock.lock() & Lock.unlock() - locking
  2. Using Memory Barriers - volatile to publish state (Can only support 1 producer & 1 consumer)
  3. CAS - Lock Free - Using Atomic variables




http://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem



http://concurrencykit.org/presentations/lockfree_introduction/#/


Lock-Free Algorithms

Wait-Free Algorithms

  1. memory barrier, also known as a membar, memory fence or fenceinstruction, is a type of barrier instruction that causes a central processing unit (CPU) or compiler to enforce an ordering constraint onmemory operations issued before and after the barrier instruction.
Concurrency Control

Optomistic Concurrency Control

While running, transactions use data resources without acquiring locks on those resources. Before committing, each transaction verifies that no other transaction has modified the data it has read. If the check reveals conflicting modifications, the committing transaction rolls back and can be restarted.


Why we need to use notifyAll() - The Lost Wake-Up Problem
if notify() happens between condition-check & call to wait().
http://docs.oracle.com/cd/E19455-01/806-5257/sync-30/index.html


Why we need to check the condition in a Loop - Spurious Wakeup -
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html


All about MultiThreading - http://tutorials.jenkov.com/java-concurrency/thread-signaling.html

Volatile


Volatile fields are instance or class (static) variables and are stored in the heap. I think if its static field it can be stored on the Method Area ( which can itself be in the Heap Area (Permgen ?) )

No comments:

Post a Comment