Difference between revisions of "Threads and Executors"

From CSE231 Wiki
Jump to navigation Jump to search
Line 14: Line 14:
  
 
==TAgeSum==
 
==TAgeSum==
implement <code>int sumUpperLowerSplit(int[] ages, ThreadFactory threadFactory)</code>
+
===implement <code>int sumUpperLowerSplit(int[] ages, ThreadFactory threadFactory)</code>===
 +
 
 +
You will need use the passed in ThreadFactory to create a thread or two (at your preference), start any threads you create, and join them.
 +
 
 +
Think about where you need to start and join them to ensure both correctness and an appropriate amount of parallelism.
  
 
=Executors=
 
=Executors=

Revision as of 21:42, 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 thread or two (at your preference), start any threads you create, and join them.

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

Executors

XNucleobaseCount

XQuicksort