com.threed.jpct.threading
Class Worker

java.lang.Object
  extended bycom.threed.jpct.threading.Worker

public class Worker
extends java.lang.Object

A simple multi-threading framework that jPCT uses to speed up some operations on multicore cpus. You are free to use it in your own application by creating your own Worker instance.


Constructor Summary
Worker(int queues)
          Creates a new Worker.
 
Method Summary
 void add(WorkLoad wl)
          Adds a new WorkLoad to the queue with the least load.
 void add(WorkLoad wl, int queue)
          Adds a new WorkLoad to the given queue.
 void dispose()
          Terminates the worker and all running threads.
 void finalize()
           
 int getQueueCount()
          Returns the number of queues that the Worker actually uses.
 boolean isDone(WorkLoad wl)
          Is the Worker already done with a given WorkLoad?
 void waitFor(java.lang.Class type)
          Waits for all WorksLoads that are instances of the given Class to be processed.
 void waitForAll()
          Waits for all WorkLoads to be processed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Worker

public Worker(int queues)
Creates a new Worker. The worker will spawn some threads (depending on the number of queues), each thread will process one queue and sleeps if there's nothing to process. If queue is set to 1 no threads will be spawned at all and any WorkLoad given to the Worker will be executed immediately instead.

Parameters:
queues - the maximal number of queues, i.e. the maximum number of threads being spawned
Method Detail

isDone

public boolean isDone(WorkLoad wl)
Is the Worker already done with a given WorkLoad? This method will always return true on Workers with only one queue.

Parameters:
wl - the WorkLoad
Returns:
is it done?

getQueueCount

public int getQueueCount()
Returns the number of queues that the Worker actually uses.

Returns:
the number

waitForAll

public void waitForAll()
Waits for all WorkLoads to be processed.


waitFor

public void waitFor(java.lang.Class type)
Waits for all WorksLoads that are instances of the given Class to be processed.

Parameters:
type - the class

add

public void add(WorkLoad wl,
                int queue)
Adds a new WorkLoad to the given queue. If the queue number is too high, it will be taken modulo the actual number. If the Worker has only one queue, this method will execute the WorkLoad immediatly and return afterwards.
If you are calling this method inside another WorkLoad which is bound to the this queue, the new WorkLoad will be executed immediately.

Parameters:
wl - the WorkLoad
queue - the queue

add

public void add(WorkLoad wl)
Adds a new WorkLoad to the queue with the least load. If the Worker has only one queue, this method will execute the WorkLoad immediately and return afterwards.
If you are calling this method inside another WorkLoad which is bound to the least loaded queue, the new WorkLoad will be executed immediately.

Parameters:
wl - the WorkLoad

dispose

public void dispose()
Terminates the worker and all running threads.


finalize

public void finalize()