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 7752577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:50:07+00:00 2026-06-01T11:50:07+00:00

I have 3 classes. A Waiter (thread), a Table (thread), and a Queue (not

  • 0

I have 3 classes. A Waiter (thread), a Table (thread), and a Queue (not a thread) (simiple first in first out queue).

Initially a couple of waiters are created and then tables are created. There are many more tables than waiters so tables have to “wait” for waiters to serve them. I am supposed to use “java synchronization primitives, wait notify, and notifall” to solve this problem. Here are the guidelines for each class:

Table:
When it is started, it enters the queue and then calls an internal method waitService() which returns if it has been serviced or waits for a waiter.

the way I have this method right now:

$if(serviced)
        return 0;
    try {
        this.wait();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Waiter:
The waiter code is not really giving me any issues but essentially the way it works is that in the run method there is an infinite loop that checks if there is a table waiting and then gives that table service for a random amount of time after which it checks if another table is waiting. It lets the table know it is giving it service by calling giveService() method inside the table class.

Queue:
It has a list of waiters and a list of tables. The waiter calls nextTable() in the queue class when it is ready to give service. this is how I have it set up:

$public Table nextTable(Waiter w) throws InterruptedException {

    if(closed)
        return null;
    if(tables.isEmpty()) {
        w.wait();
    }
    Table t =  tables.removeFirst();
    t.notify();
    return t;   
}

I know the above may have some very fundamental mistakes but essentially I have no clue how synchronization primitives work in java. Any help would be appreciated.

  • 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-01T11:50:08+00:00Added an answer on June 1, 2026 at 11:50 am

    This is as good of a tutorial as any on using wait(), notify() and notifyAll(). Read through it first, and see if you have additional questions that either SO hasn’t already answered, or something in particular to your problem.

    http://www.java-samples.com/showtutorial.php?tutorialid=306

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

Sidebar

Related Questions

For example, I have a main thread, there is created a lot of classes
I have a couple extension methods that handle serialization of my classes, and since
I am still struggling with understanding classes, I am not certain but I have
I have created a method that accepts an object then attempts to serialize the
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have classes that are named exactly the same across different plug-ins that I
I have classes which have automatic properties only like public customerName {get; set;}. They
I have classes that are needed in both my web service and my server.
I have classes structured like this: Public MustInherit Class A ' several properties End
I have classes *ColorViewController *DrawRectangle In ColorViewController.h: #import DrawRectangle.h @interface ColorViewController : UIViewController {

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.