Difference between revisions of "Threads and Executors"
Jump to navigation
Jump to search
implement
implement
Line 18: | Line 18: | ||
You will need use the passed in ThreadFactory to [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadFactory.html#newThread-java.lang.Runnable- create a new thread] or two (at your preference), [https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#start-- start] any threads you create, and [https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#join-- join] them. | You will need use the passed in ThreadFactory to [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadFactory.html#newThread-java.lang.Runnable- create a new thread] or two (at your preference), [https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#start-- start] any threads you create, and [https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#join-- join] them. | ||
− | Think about where you need to start and join | + | Think about where you need to start and join any Threads to ensure both correctness and an appropriate amount of parallelism. |
=Executors= | =Executors= |
Revision as of 21:46, 24 September 2017
Contents
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.