edu.stanford.nlp.util.concurrent
Class MulticoreWrapper<I,O>

java.lang.Object
  extended by edu.stanford.nlp.util.concurrent.MulticoreWrapper<I,O>
Type Parameters:
I - input type
O - output type

public class MulticoreWrapper<I,O>
extends java.lang.Object

Provides convenient multicore processing for threadsafe objects. Objects that can be wrapped by MulticoreWrapper must implement the ThreadsafeProcessor interface. TODO(spenceg): Make lastSubmittedId and lastReturnedId threadsafe. Should support independent threads writing and reading from the queue.

Author:
Spence Green

Constructor Summary
MulticoreWrapper(int nThreads, ThreadsafeProcessor<I,O> processor)
           
 
Method Summary
 boolean hasNext()
          Indicates whether a not a new result is available.
 boolean join()
          Waits for all active processes to finish, then returns true only if all results have been returned via calls to next().
 O next()
          Returns the next available result.
 void submit(I inputInstance)
          Allocate instance to a process and return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MulticoreWrapper

public MulticoreWrapper(int nThreads,
                        ThreadsafeProcessor<I,O> processor)
Method Detail

submit

public void submit(I inputInstance)
Allocate instance to a process and return. This call blocks until I can be assigned to a thread.

Parameters:
inputInstance -

join

public boolean join()
Waits for all active processes to finish, then returns true only if all results have been returned via calls to next().

Returns:
True on successful shutdown, false otherwise.

hasNext

public boolean hasNext()
Indicates whether a not a new result is available.

Returns:
true if a new result is available, false otherwise.

next

public O next()
Returns the next available result.

Returns:


Stanford NLP Group