Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:04:39+00:00 2026-06-02T09:04:39+00:00

i need to write a java program but i need some advice before starting

  • 0

i need to write a java program but i need some advice before starting on my own.

The program i will be writing is to do the following:

  • Simulate a shop takes advanced order for donuts

  • The shop would not take further orders, once 5000 donuts have been ordered

Ok i am kind of stuck thinking if i should be writing the java-class to act as a Monitor or should i use Java-Semaphore class instead?

Please advice me. Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:04:41+00:00Added an answer on June 2, 2026 at 9:04 am

    Any java object can work as a monitor via the wait/notify methods inherited from Object:

    Object monitor = new Object();
    
    // thread 1    
    synchronized(monitor) {
        monitor.wait();
    }
    
    // thread 2
    synchronized(monitor) {
        monitor.notify();
    }
    

    Just make sure to hold the lock on the monitor object when calling these methods (don’t worry about the wait, the lock is released automatically to allow other threads to acquire it). This way, you have a convenient mechanism for signalling among threads.

    It seems to me like you are implementing a bounded producer-consumer queue. In this case:

    1. The producer will keep putting items in a shared queue.
    2. If the queue size reaches 5000, it will call wait on a shared monitor and go to sleep.
    3. When it puts an item, it will call notify on the monitor to wake up the consumer if it’s waiting.
    4. The consumer will keep taking items from the queue.
    5. When it takes an item, it will call notify on the monitor to wake up the producer.
    6. If the queue size reaches 0 the consumer calls wait and goes to sleep.

    For an even more simplified approach, have a loop at the various implementation of BlockingQueue, which provides the above features out of the box!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a program in Java which will read a relatively large
I need to write a Perl script that pipes input into a Java program.
I need to write a standalone Java application which will have a embedded HTTP
I need to write a MultiThreaded Java Application that will be used to load
Basically, I just need to write a simple java program to detect the version
I need to write a simple terminal-based program that should, Read some text from
I need to write a Java Comparator class that compares Strings, however with one
I need to write a java script. This is supposed to validate if the
I need to write a java application which can merge docx files. Any suggestions?
I need to write a java JCE provider. I have been looking in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.