C# Class multithreading.JobCenter.Worker

Represents a worker. A worker does work. One can assign as many jobs to him, as one likes. They all get stored in a queue, which the worker works on. You can rest while he's doing your work and he will wake you up, if he's finished. If there are no jobs to do for the moment, the worker rests, releasing system resources. A worker is implemented as a thread, so creating multiple workers and letting them work on independent jobs grants a performance benefit on multi processor systems. Or you just can realize asnychronous operations (on a single processer system).
显示文件 Open project: denniskb/asvo

Public Properties

Property Type Description
id int

Public Methods

Method Description
Worker ( )

Creates a new worker and assigns it a unique id. Workers should be reused throuout the execution time rather than being destroyed and recreated.

assignJob ( IJob job ) : void

Assigns this worker a job which gets inserted into the worker's job queue.

getWorkerCount ( ) : int

Returns the count of all created workers since application start.

join ( ) : void

Puts the calling thread to sleep, until the worker has finished all his work.

start ( ) : void

Starts this worker's every day work described in the class summary.

Private Methods

Method Description
doWork ( ) : void

(Fetch job -> execute -> sleep)-loop described in the class summary.

Method Details

Worker() public method

Creates a new worker and assigns it a unique id. Workers should be reused throuout the execution time rather than being destroyed and recreated.
public Worker ( )

assignJob() public method

Assigns this worker a job which gets inserted into the worker's job queue.
public assignJob ( IJob job ) : void
job IJob The job to be exectued by the worker.
return void

getWorkerCount() public static method

Returns the count of all created workers since application start.
public static getWorkerCount ( ) : int
return int

join() public method

Puts the calling thread to sleep, until the worker has finished all his work.
public join ( ) : void
return void

start() public method

Starts this worker's every day work described in the class summary.
public start ( ) : void
return void

Property Details

id public_oe property

public int id
return int