Difference between revisions of "Threads and Executors"

From CSE231 Wiki
Jump to navigation Jump to search
Line 22: Line 22:
 
=Executors=
 
=Executors=
 
==XNucleobaseCount==
 
==XNucleobaseCount==
 +
===note int countSequential(byte[] chromosome, Nucleobase nucleobase)===
 +
<code>
 +
public static int countSequential(byte[] chromosome, Nucleobase nucleobase) {
 +
return countRangeSequential(chromosome, nucleobase, 0, chromosome.length);
 +
}
 +
</code>
 +
===implement <code>int countRangeSequential(byte[] chromosome, Nucleobase nucleobase, int min, int max)</code>===
 +
===implement <code>int count2WaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)</code>===
 +
===implement <code>int countNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks)</code>===
 +
===implement <code>int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)</code>===
 +
===implement <code>int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)</code>===
  
 
==XQuicksort==
 
==XQuicksort==

Revision as of 21:49, 24 September 2017

Threads

class SimpleThreadFactory

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

XNucleobaseCount

note int countSequential(byte[] chromosome, Nucleobase nucleobase)

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)

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