• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Allowing multiple threads into a monitor?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have 3 resources that I am controlling access to, is there a way to allow 3 threads access to the resources using a monitor? Or are monitors strictly mutual exclusion?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, a Semaphore (from the java.util.concurrent package) sounds like just the thing you're looking for.
 
Tim Crouch
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! This is actually for a homework assignment where the first part required the use of a counting semaphore to solve the same problem, and I got that working like a charm. But now the next part is to solve the same problem with a monitor, and once I add "synchronized" to the method that gives out the protected resources, it only allows in one thread at a time no matter what I do. Several people in my class have complained about this same problem, but I just wanted to try to exhaust every avenue before I slap another semaphore on it and call it a day lol. I have been researching and looking through links for hours trying to find an answer, but they all point to semaphores as being the answer for that problem.

I guess I was just trying to see if there was any way at all to do this with a monitor before conceding that it can't be done that way and going with the way I know works but isn't exactly what was asked for.

Thank you again
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you're supposed to write your own version of Semaphore using a monitor?
 
Tim Crouch
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what we did in the first part, but the professor did seem to kind of cryptically agree that part 1 and 2 were a lot alike. He allows us to correct mistakes, so I guess I will just do that and see if he complains about it lol.

Thank you for the help!
 
reply
    Bookmark Topic Watch Topic
  • New Topic