Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Laborer program

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Default Laborer program


    Implement a generic laborer mechanism that can be used by an application to perform various types of processing.

    A laborer is an autonomous processing engine that uses its own processing resources (e.g. threads) to do its work.
    Each Worker should be able to process its own types of Work. laborers should perform their processing in an asynchronous way,
    NOT delaying in any way the hosting application's threads. Workers should operate in three states, INITIAL, OPERATIONAL and STOPPED as explained below:

    - INITIAL: State right after laborers istantiation, NOT for processing Work.
    - OPERATIONAL: State in which, laborers normally accept and process Work.
    - STOPPED: State indicating possible imminent shutdown, NOT for processing Work.

    The hosting application must be able to interact with Worker implementations via well defined interfaces. Specifically and at a minimum:

    - An interface to control the life cycle of a laborer and to submit Work units.
    - An interface or abstract class as the root of the Work unit hierarchy.

    The interfaces should support Java Generics, to provide compile-time type safety to the hosting application's developers.
    The interfaces should be possible to be used in the following ways:
    - laborer<SomeWork> laborer = new SomeWorklaborer<SomeWork>();
    - Attempting to submit SomeOtherWork to a Worker<SomeWork> should be reported as a compile-time error.

    The following state transitions should be supported: <NOT EXISTS> --> INITIAL --> OPERATIONAL <--> STOPPED

    laborers should use their own threads and thread pools to perform their processing, according to the processing needs of each implementation.
    The only restrictions imposed regarding threads and thread pools are the following:

    - When in the INITIAL or STOPPED states, a laborer should NOT have ANY threads alive.
    - Transitioning into the OPERATIONAL state, a laborer should create and initialize its threads or thread pools.
    - Transitioning from the OPERATIONAL to the STOPPED state, a laborer should ensure that when the hosting application's thread returns from the
    transition-triggering method, processing of ALL Work units being actively processed by the laborer's threads HAS FINISHED.

    laborers should also make use of queueing mechanisms to both be able to accept Work units for processing even when all their processing resources are busy,
    and not impose any delays to the hosting application's threads. To prevent out-of-memory conditions, Workers should indicate their inability to further
    queue additional Work units, when their queues already have "many" items, by throwing an appropriate exception to the calling hosting application.


    To demonstrate use of the mechanism as well as to prove its correct operation, an example laborer should be implemented to use the TempConvert Web
    Service (TempConvert Web Service) to convert temperatures between Celcius and Fahrenheit. The temperature as well as
    the conversion to perform should be parameters of the corresponding Work unit. The Worker should perform no more than 5 concurrent calls to the Web Service,
    but also should not be limited to one, and it should be able to queue up to 20 Work units.

    The demostrating program should create an instance of the laborer, submit a few Work units with various combinations of temperatures and conversions
    (demonstrating normal operation) and then attempt to saturate the queue by rapid submission of many Work units. It should then demonstrate state
    transitions and exit.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 632 Times in 540 Posts

    Default Re: Laborer program

    Did you have a question?

    Recommended reading: How to Program (stuck on homework? READ THIS BEFORE POSTING)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM