See module attached:
The module simulates a museum's walkman rentals at 5.00 a piece and a total of 50 walkmans, and groups between 1 and 7 visitors. I want to have counter threads(3) so that the results would be:
Counter 0 wants 1
Counter 0 acquires 1
Status: Deposits 5 Walkman 49
Counter 1 wants 4
Counter 1 acquires 4
Status: Deposits 25 Walkman 45
then when stock runs out counters must wait till the stock is replenished, via deposit()...
i.e if there were only 2 tape players left and all groups at the counter were larger than 2 visitors, then no group could proceed.
and message should say:
Counter 1 wants 4
Counter 2 wants 2
Counter 2 acquires 2.....
Thanks hope that is clear....
This is not quite right.
I've checked your code and there is no connection between the rentals
and the receivals, e.g. the getStockBalance() method in Walkman (is a
hack that) handles returns that exceed the original Walkman storage.
As I see it you should have another class (say Entry) that spawned
visitor groups that hired and returned the same number of walkmen, and
Sounds good can you give me an example of what you mean, Thanks?
Here is some pseudo code.
If you establish a code sceleton I may can have a look at it.
App creates Entry.
App Creates Countes and starts the Counter threads that go to sleep immediately.
App starts Entry
Entry spawns (creates) one VisitorGroup each 4 sec.
Entry assigns the VisitorGroup a headcount of between 3-10 visitors.
Entry directs the VisitorGroup to one of the available Counters
This is done by interrupting the Counter thread (e.g. waking it up)
The Counter rents walkmen to the VisitorGroup if it has enough in stock.
-if not, the Counter waits for a little while.
(the Counter operates an internal stack of VisitorGroups that serves as the Counter que)
The counter starts the VisitorGroup after having rented out the walkmen.
The Counter then checks its queue, if any VisitorGroup found the Counter attempts a new rental/start.
-if queue is empty it sleeps for a long time, as in the start.
The visitor group goes for a tour of, say, 7-10 sec, - e.g. sleeps.
On wakeup the VisitorGroup returns the walkmen to the Counter and exits. - this
implies that a VisitorGroup must 'know' whicj Counter it rents from.
The Counter interrupts its own sleep (if sleeping) when the VisitorGroup-returnal method is called.
Last edited by sjalle; 04-21-2005 at 07:57 AM.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL