File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Threads and priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads and priority" Watch "Threads and priority" New topic

Threads and priority

Samir Aguiar

Joined: Mar 19, 2013
Posts: 1
Hello there,

I have an assignment where I need to simulate a parking lot.
The cars will stay in a waiting line while all the parking places are being used.
After one of them is freed, one car from the waiting line can park.
There are three kind of users. F users take priority over A users, while D users take priority over both F and A users.

So I have three threads, D, F and A.
I also have three more classes, Car, ParkingLot and Main.

ParkingLot is shared between the three threads, and each thread has a Car object.
ParkingLot has methods to take a parking place, release a parking place, take a place in the waiting line, release a place in the waiting line and some others.

The Main class will create the threads and start them. The threads will then try to park, and when the parking lot is full they'll be waiting.

The waiting line and the parking places are arrays of Car objects.

Here's the method to park, which is called by the three threads:

My problem is: how do I set the priority for the threads? I tried to use setPriority(), but to no avail.

Any ideas?
I'm also not sure if my implementation is right, so I appreciate any advice on this.

Best regards,
I agree. Here's the link:
subject: Threads and priority
jQuery in Action, 3rd edition