Difference between revisions of "Threads and Executors"
Jump to navigation
Jump to search
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | This assignment has been updated: [[Thread_and_Executor_Service_Assignment|Thread and ExecutorService]] | ||
+ | <!-- | ||
credit for this assignment: [[User:Finn|Finn Voichick]] and [[User:cosgroved|Dennis Cosgrove]] | credit for this assignment: [[User:Finn|Finn Voichick]] and [[User:cosgroved|Dennis Cosgrove]] | ||
=Motivation= | =Motivation= | ||
Line 87: | Line 89: | ||
==Executors== | ==Executors== | ||
− | <youtube>8qh9LMhvNXI</youtube | + | <youtube>8qh9LMhvNXI</youtube> |
− | + | <youtube>tuAkLb99sLE</youtube> | |
− | <youtube>tuAkLb99sLE</youtube | ||
===Code To Use=== | ===Code To Use=== | ||
Line 107: | Line 108: | ||
As always, the [[Reference_Page#Executors|wiki's reference page]] can be of help. | As always, the [[Reference_Page#Executors|wiki's reference page]] can be of help. | ||
− | |||
− | |||
===Mistake To Avoid: Do NOT call shutdown=== | ===Mistake To Avoid: Do NOT call shutdown=== | ||
Each method you write will be passed an executor. You need not (and should NOT) invoke [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html#shutdown-- shutdown()]. That is the responsibility of whoever created the executor. For example, a JUnit test would do this if it was appropriate (i.e. it created an executor and was not using the [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html#commonPool-- common pool]). | Each method you write will be passed an executor. You need not (and should NOT) invoke [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html#shutdown-- shutdown()]. That is the responsibility of whoever created the executor. For example, a JUnit test would do this if it was appropriate (i.e. it created an executor and was not using the [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html#commonPool-- common pool]). | ||
− | |||
===XNucleobaseCount=== | ===XNucleobaseCount=== | ||
Line 118: | Line 116: | ||
{{CodeToImplement|XNucleobaseCount|countLowerUpperSplit<br>countNWaySplit<br>countDivideAndConquer<br>countDivideAndConquerKernel|tnx.lab.executor}} | {{CodeToImplement|XNucleobaseCount|countLowerUpperSplit<br>countNWaySplit<br>countDivideAndConquer<br>countDivideAndConquerKernel|tnx.lab.executor}} | ||
− | {{Tip|Use [ | + | {{Tip|Use [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/count/lab/NucleobaseCounting.html#countRangeSequential(byte%5B%5D,edu.wustl.cse231s.bioinformatics.Nucleobase,int,int) countRangeSequential()] from [[Nucleobase_Counting]]}} |
====lower upper split==== | ====lower upper split==== | ||
{{Parallel|int countLowerUpperSplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)}} | {{Parallel|int countLowerUpperSplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)}} | ||
Line 159: | Line 157: | ||
{{Warning|Unlike in Sarkar's and McDowell’s videos which use inclusive maximums, CSE 231 consistently uses exclusive maximums to avoid having to subtract 1 all of the time.}} | {{Warning|Unlike in Sarkar's and McDowell’s videos which use inclusive maximums, CSE 231 consistently uses exclusive maximums to avoid having to subtract 1 all of the time.}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
====Code To Use==== | ====Code To Use==== | ||
Line 173: | Line 165: | ||
:[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/sort/core/quick/PivotLocation.html#getRightSidesLowerInclusive-- getRightSidesLowerInclusive()] | :[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/sort/core/quick/PivotLocation.html#getRightSidesLowerInclusive-- getRightSidesLowerInclusive()] | ||
− | + | Note: Investigate SequentialPartitioner. | |
− | SequentialPartitioner | ||
− | + | ====XSequentialQuicksorter==== | |
− | |||
{{CodeToImplement|XSequentialQuicksorter|sortRange|tnx.lab.executor}} | {{CodeToImplement|XSequentialQuicksorter|sortRange|tnx.lab.executor}} | ||
Line 190: | Line 180: | ||
{{Parallel|private void kernel(Queue<Future<?>> futures, T[] data, Comparator<T> comparator, int min, int maxExclusive)}} | {{Parallel|private void kernel(Queue<Future<?>> futures, T[] data, Comparator<T> comparator, int min, int maxExclusive)}} | ||
+ | |||
+ | {{Tip | Be sure to <code>test</code> the <code>isParallelPredicate</code> to determine if the current range length is worthy of parallel processing or if you should fall back to the <code>sequentialSorter</code>. }} | ||
{{Sequential|public void sortRange(T[] data, Comparator<T> comparator, int min, int maxExclusive)}} | {{Sequential|public void sortRange(T[] data, Comparator<T> comparator, int min, int maxExclusive)}} | ||
Line 249: | Line 241: | ||
=Pledge, Acknowledgments, Citations= | =Pledge, Acknowledgments, Citations= | ||
{{Pledge|lab-threads-and-executors}} | {{Pledge|lab-threads-and-executors}} | ||
+ | --> |
Latest revision as of 19:40, 22 February 2022
This assignment has been updated: Thread and ExecutorService