Java Program Using Threads

Hi there, im really new and have just started programming in Java, i have to create a java program which implement threads. Thread.Wait, thread.start them etc.

Here is the problem, any guidance would be great cheers guys

The manager of a company employs 3 secretaries who are of varying ability, but who all work extremely fast. Secretary A is the most experienced secretary and is capable of typing up a letter once every second. Secretary B is less experienced and is capable of typing up a letter once every 2 seconds. Secretary C is the junior secretary and is capable of typing up a letter once every 4 seconds. When a secretary has typed up a letter he leaves it in the manager抯 tray for him to remove and sign. The manager removes and signs a letter from the tray once every 2 seconds. The tray can hold a maximum of 5 letters at a time. The tray抯 limited capacity sometimes causes the various workers to be delayed. For example, if the tray is full after a letter has been typed, the secretaries must wait until the manager makes a space available before they can add another letter to the tray. Similarly, the manager must wait for at least one letter to appear in the tray before he can take it out and sign it.

In your program, make use of threads to represent each of the workers (the 3 secretaries and the manager), so that they can work in parallel. You will also need to declare a tray object, and ensure that all communication is properly synchronised to avoid indeterminacy and deadlock. While an office worker is busy typing a letter or signing it, you should send that thread to sleep for the appropriate time period. This can be achieved with a call to:

Thread.sleep(m);

where m is the number of milliseconds for which the thread should suspend.

The output from your program should take the form of a running commentary on the activity taking place in the office. An extract from it might look something like this (though it is up to you how you word this):

?.

Secretary A is ready to type a letter

Secretary A has typed a letter, number now typed = 6

Tray full. Secretary must wait until a letter has been removed before adding another

Secretary C has typed a letter, number now typed = 2

Tray full. Secretary must wait until a letter has been removed before adding another

A letter has been removed from the tray. Tray = 4

The Manager has taken a letter from the tray to sign, number signed = 4

The Manager is ready to sign a letter

etc

?.

Run your simulation until the secretaries have typed and filed 7 letters each, and the manager has removed and signed all 21 letters.

Thanks again

[2730 byte] By [brownscidz8a] at [2007-11-26 18:50:36]
# 1
WIthout you at least taking a stab at it and posting code (properly enclosed between [code] and [/code] tags, of course) and specifics about what's giving you trouble, the best I can suggest is to start here: http://java.sun.com/docs/books/tutorial/essential/concurrency/
jverda at 2007-7-9 6:24:38 > top of Java-index,Java Essentials,New To Java...
# 2
Jverd, how do you get code tags to display like that, as plain text?Cheers.
kikemellya at 2007-7-9 6:24:38 > top of Java-index,Java Essentials,New To Java...
# 3
> Jverd, how do you get code tags to display like that,> as plain text?Reply to his post and click "Quote Original". You'll see how it is done there.
DrClapa at 2007-7-9 6:24:38 > top of Java-index,Java Essentials,New To Java...
# 4
> > Jverd, how do you get code tags to display like> that,> > as plain text?> > Reply to his post and click "Quote Original". You'll> see how it is done there.Nice one, thanks. That has bugged me for ages.
kikemellya at 2007-7-9 6:24:38 > top of Java-index,Java Essentials,New To Java...
# 5
I would have a stab at it, but i dont even know where to begin, im really new to java, i know what the thread.start commands do etc but i just dont know how to prgram them to get a result if you understandThanks for the help anyway
brownscidz8a at 2007-7-9 6:24:39 > top of Java-index,Java Essentials,New To Java...
# 6

Then you're probably better off enlisting one-on-one, in-person help from your instructor, a classmate, or a private tutor, or joining a study group. Forums like this are not well-suited to tutoring you from the ground up.

If you're doing multithreaded homework and you don't even know where to start, it sounds like ether the instructor is horrible or you're in over your head, or you just haven't been keeping up with the class.

Good luck.

jverda at 2007-7-9 6:24:39 > top of Java-index,Java Essentials,New To Java...