Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.

Similar presentations


Presentation on theme: "Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a."— Presentation transcript:

1 Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a threaded program, you can have multiple threads working concurrently.

2 Concurrency (Threads) Concurrency is achieved through time-slicing. This is where the processor cycles through each active thread for an indeterminate period of time (the slice). This gives the illusion that there are multiple processes. With multi-core processors, this may mean, true multi-threading is possible, but NOT guaranteed

3 Thread Pools Thread Pools manage (and limit) the number of active threads. This tends to be more orderly and more efficient for scaled applications.

4 Synchronizing methods When multiple threads have access to the same object, it makes sense to synchronize those methods which are prone to concurrency errors. The bank account example.

5 Thread-safe collections //http://download.oracle.com/javase/6/docs/a pi/java/util/concurrent/package- summary.html

6 Searching Linear search O(n) --slow Binary search O(log 2 n) --fast Refresher on logs: If 2 3 = 8 then log 2 8 = 3 Hashed search O(1) –fastest Search driver class

7

8 Sorting SelectionSort O(n 2 ) –-slow MergeSort O(n * log 2 n) –- fast HeapSort O(n * log 2 n) –- fast QuickSort O(n * log 2 n) –- fast


Download ppt "Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a."

Similar presentations


Ads by Google