Masudul Haque
Process-based multitasking
• Allows you to run the Java Compiler at the same time that
you are using an editor

Thread-bas...



Implement Runnable interface
Subclass Thread class


Thread execution
◦ start() – Start a thread by calling its run() method
◦ run() – Entry point for the thread



Thread...


Thread lifetime and termination
◦ isAlive() – Determine if a thread is still running
◦ join() – Wait for a thread to te...




A concurrent application's ability to execute
in a timely manner is known as its liveness
Deadlock describes a situa...



Thread interference
Memory Consistency Error
java.util.concurrent
• Concurrency APIs
java.util.concurrent.atomic
• Atomic data types
java.util.concurrent.locks

• Lock...
Semaphore
• Implements the classic semaphore
CountDownLatch
• Waits until a specified number of events have occurred
Cycli...
Executor

Future

ExecutorService

ThreadPool
Executor

ScheduledPool
Executor

Callable


Executor Interface
◦ Executor
◦ ExecutorService
◦ SheduledThreadExecutorService




Fork/Join
Thread Pools
◦ ThreadPo...
Concurrent
HashMap

Concurrent
LinkedQueue

CopyOnWrite
ArrayList

Array
BlockingQueue

Concurrent
SkipListMap

Concurrent...
DAYS
NANO
SECONDS

MILLI
SECONDS

HOURS

TimeUnit
Enumeration
MINUTES

MICRO
SECONDS

SECONDS
Lock

ReadWriteLock

ReentrantLock

Reentrant
ReadWriteLock
AtomicInteger
AtomicLong
decrementAndGet()

compareAndSet()

addAndGet()
Independent of
scheduling and
interleaving
Behaves
correctly
(unambiguous)

Without
additional
synchronization

Thread
saf...
synchronized
volatile

• The primary mechanism for
synchronization
• Enables the thread to bypass the cache
when accessing...
Java-7 Concurrency
Upcoming SlideShare
Loading in...5
×

Java-7 Concurrency

398

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
398
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
35
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Java-7 Concurrency

  1. 1. Masudul Haque
  2. 2. Process-based multitasking • Allows you to run the Java Compiler at the same time that you are using an editor Thread-based multitasking • A text editor can format text at the same time that it is printing
  3. 3.   Implement Runnable interface Subclass Thread class
  4. 4.  Thread execution ◦ start() – Start a thread by calling its run() method ◦ run() – Entry point for the thread  Thread blocking ◦ sleep() – Suspend a thread for a period of time ◦ yield() – Voluntarily relinquish thread control to another thread of the same priority
  5. 5.  Thread lifetime and termination ◦ isAlive() – Determine if a thread is still running ◦ join() – Wait for a thread to terminate  Thread communication ◦ wait() – Instructs the calling thread to give up the monitor and sleep until some other thread enters the same monitor and calls notify() ◦ notify() – Wakes up a thread that called wait() on the same object ◦ notifyAll() – Wakes up all threads that called wait() on the same object
  6. 6.   A concurrent application's ability to execute in a timely manner is known as its liveness Deadlock describes a situation where two or more threads are blocked forever ◦ Starvation describes a situation where a thread is unable to gain regular access to shared resources ◦ A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then livelock may result.
  7. 7.   Thread interference Memory Consistency Error
  8. 8. java.util.concurrent • Concurrency APIs java.util.concurrent.atomic • Atomic data types java.util.concurrent.locks • Locks for synchronization
  9. 9. Semaphore • Implements the classic semaphore CountDownLatch • Waits until a specified number of events have occurred CyclicBarrier • Enables a group of threads to wait at a predefined execution point Exchanger • Exchanges data between two threads
  10. 10. Executor Future ExecutorService ThreadPool Executor ScheduledPool Executor Callable
  11. 11.  Executor Interface ◦ Executor ◦ ExecutorService ◦ SheduledThreadExecutorService   Fork/Join Thread Pools ◦ ThreadPoolExecutor ◦ ScheduledThreadPoolExecutor
  12. 12. Concurrent HashMap Concurrent LinkedQueue CopyOnWrite ArrayList Array BlockingQueue Concurrent SkipListMap Concurrent SkipListSet CopyOnWrite ArraySet DelayQueue LinkedBlocking Deque LinkedBlocking Queue Prioirty BlockingQueue Synchronous Queue
  13. 13. DAYS NANO SECONDS MILLI SECONDS HOURS TimeUnit Enumeration MINUTES MICRO SECONDS SECONDS
  14. 14. Lock ReadWriteLock ReentrantLock Reentrant ReadWriteLock
  15. 15. AtomicInteger AtomicLong decrementAndGet() compareAndSet() addAndGet()
  16. 16. Independent of scheduling and interleaving Behaves correctly (unambiguous) Without additional synchronization Thread safe
  17. 17. synchronized volatile • The primary mechanism for synchronization • Enables the thread to bypass the cache when accessing the data
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×