• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to request monitor info on/from a locked object

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java Guru's
Scenario: The Classic Producer - Cubbyhole - Consumer example from Sun Microsystems



My challenge
I'm writing a "third thread" called "monitor_status".
Via this 3rd thread I want to
- get information out of the (java object) monitor that guards the Cubyhole object.
- to monitor the Thread.status of both the Producer and the Consumer threads.

Via the Thread. getState() Is can see in which status a thread is [new],[runnable][,...], etc...
I have not discovered any "java.lang.Object" Class method that provides access to monitor/lock information.


Question:
1. Is it possible (with the example above) to get information on the status of the monitor / lock on the Cubyhole object?
2. Is it possible to look into the monitors ENTER_queue and WAIT_queue? (to see which calling thread are in which monitor_queue)
or...
3. Do i have to rewrite this example to make use of the "java.util.concurrent.locks" Lock object instead of wait(), notify() methods?


I do have found the java.lang.management.MonitorInfo Class, but i can not find a good example that shows me how to use it.
4. Do you have an code-example on how to use this class?

Thanks for sharing your insight on this java monitor / object lock matter.



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!