Difference between revisions of "Threads and Executors"

From CSE231 Wiki
Jump to navigation Jump to search
Line 57: Line 57:
  
 
===implement <code>int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)</code>===
 
===implement <code>int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)</code>===
 
NOTE: ConcurrentLinkQueue's iterators are weakly consistent.  Do the warm up to see how to handle this.
 
  
 
===implement <code>int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)</code>===
 
===implement <code>int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)</code>===

Revision as of 17:43, 25 September 2017

Where To Start

Tutorial

Java 8 Concurrency Tutorial: Threads and Executors

ThreadsAndExcutorsTestSuite

Join All Warm Up

source: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html

"Iterators are weakly consistent, returning elements reflecting the state of the queue at some point at or since the creation of the iterator."

JoinAllTestSuite

ThreadsEventually joinAllInQueueViaPoll

Threads

class SimpleThreadFactory

Video

Thread Start and Join

implement Thread newThread(Runnable target)

Create and return a new thread with the target Runnable parameter you are passed.

Do *NOT* start this thread.

Certainly, do *NOT* run this thread.

Do not pass Go. Do not collect $200.

To repeat: just create a new Thread with the target Runnable and return it.

TAgeSum

implement int sumUpperLowerSplit(int[] ages, ThreadFactory threadFactory)

You will need use the passed in ThreadFactory to create a new thread or two (at your preference), start any threads you create, and join them.

Think about where you need to start and join any Threads to ensure both correctness and an appropriate amount of parallelism.

Executors

Videos

Executor submit and Future get

Executor invokeAll

XNucleobaseCount

note countSequential

public static int countSequential(byte[] chromosome, Nucleobase nucleobase) {
	return countRangeSequential(chromosome, nucleobase, 0, chromosome.length);
}

implement int countRangeSequential(byte[] chromosome, Nucleobase nucleobase, int min, int max)

implement int count2WaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)

implement int countNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks)

Use SliceUtils

implement int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)

implement int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)

XQuicksort

note sequentialQuicksort

public static void sequentialQuicksort(int[] array) {
	sequentialQuicksortKernel(array, 0, array.length);
}

implement void sequentialQuicksortKernel(int[] array, int min, int maxExclusive)

implement void parallelQuicksort(ExecutorService executor, int[] array, int threshold)

implement void parallelQuicksortKernel(ExecutorService executor, int[] array, int min, int maxExclusive, Queue<Future<?>> futures, int threshold)

Pledge, Acknowledgments, Citations

hw3-pledge-acknowledgments-citations.txt