class ExecutorServiceResultsHandler[V] extends Iterable[V]
Wrapper around an ExecutorService that allows you to easily submit Callables, get results via iteration,
and handle failure quickly. When a submitted callable throws an exception in its thread this
will result in a RuntimeException when iterating over results. Typical usage is as follows:
- Create an ExecutorService and pass it to the constructor.
- Create Callables and ensure that they respond to interruption, e.g. regularly call:
if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("The thread was interrupted, likely indicating failure in a sibling thread.");} - Pass the callables to the
submit()method. - Call
finishedSubmitting(). - Iterate over this object (e.g. with a foreach loop) to get results from the callables.
Each iteration will block waiting for the next result.
If one of the callables throws an unhandled exception or the thread is interrupted during iteration
then
ExecutorService#shutdownNow()will be called resulting in all still running callables being interrupted, and aRuntimeExceptionwill be thrown
You can also call abort() to shut down the threads yourself.
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- ExecutorServiceResultsHandler
- Iterable
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Instance Constructors
- new ExecutorServiceResultsHandler(executorService: ExecutorService)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def abort(): Unit
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
awaitCompletion(): Unit
Convenience method to wait for the callables to finish for when you don't care about the results.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def finishedSubmitting(): Unit
-
def
forEach(arg0: Consumer[_ >: V]): Unit
- Definition Classes
- Iterable
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator(): Iterator[V]
- Definition Classes
- ExecutorServiceResultsHandler → Iterable
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
spliterator(): Spliterator[V]
- Definition Classes
- Iterable
- def submit(task: Callable[V]): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )