This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Threads and priority

 
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Samir
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!