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

  • Home
  • SEARCH
  • 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 6660081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:06:38+00:00 2026-05-26T02:06:38+00:00

I want to wait() the put() method called from the second thread which has

  • 0

I want to wait() the put() method called from the second thread which has been connected to the Server (Monitor). But when i do this, the whole GUI frames (Swing) including their elements get frozen aftr the second put() call. How to fix this? I want the second thread keep waiting till the first thread performs a get() which frees a slot. Thanks in advance. Here’s my skeleton code:

Server:

Buffer<String> buf = new Buffer<String>(1);
while(true){
   //for each socket connected           
   new ServerHandler(..., buf).start();

}

ServerHandler:

public class ServerHandler extends Thread {

  Buffer<Messenger> buf;

  public void run(){
      buf.put("Test");
  }
}

Buffer:

public class BufferImp<String>
    private String[] requests;
    private int cur_req_in; // current Request in the queue
    private int req_size;
    private int req_count;

 public BufferImp(int size) {
        this.req_size = size;
        requests = new String[size];
        this.cur_req_in = 0;
        this.req_count = 0;
    }

 public synchronized void put(E o) throws InterruptedException {

        while(req_size == req_count) this.wait();

        requests[cur_req_in] = o;
        cur_req_in = (cur_req_in + 1) % req_size;
        req_count++;
        notifyAll();


    }
}
  • 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-05-26T02:06:39+00:00Added an answer on May 26, 2026 at 2:06 am

    Don’t call wait when code is executing on the Event Dispatch Thread.

    Instead you need to create a separate Thread for your long running task,

    Read the section from the Swing tutorial on Concurrency for more information.

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

Sidebar

Related Questions

NSOperationQueue has waitUntilAllOperationsAreFinished , but I don't want to wait synchronously for it. I
Is there any neat solution of knowing when a thread has been put into
I want to wait for a process to finish, but Process.WaitForExit() hangs my GUI.
want to ask user to input something but not want to wait forever. There
I have a Java Thread which exposes a property which other threads want to
I have a web service from which i receive data, put it in a
I created a little (single thread) server and put the work-code in a Runnable
I have implemented ReaderWriterLockSlim, Now i don't want it to wait at the lock.
I just want to show text please wait while app is searching for satellite
In Javascript, I want my onmouseout event to sleep/pause/wait/ (not sure of the proper

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.