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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:00:53+00:00 2026-06-06T11:00:53+00:00

Given a really oversimplified example: Class A { B b = new B(); }

  • 0

Given a really oversimplified example:

Class A {
    B b = new B();
}

Class B {
    //unicorns and what-not
    //Something happens and I want to let A know
    //Yet I don't want to return and exit
}   

Is there any way that B can communicate with A without Sockets?
By communicate, I mean B sending values to A without A invoking a method on B.

EDIT: Thank you for your responses. This following is my follow up question:

If I had the following, and method signal() is called simultaneously by 2 instances of B, this will cause a conflict of every B calling action twice. What can I do to solve it?

//Modified from Jon Skeet
public class A {
    private B b[];

    public A() {
        //for loop
        b[i] = new B(this);
    }

    public void signal() {
        //for loop
        b[i].action();
    }
}

public class B {
    A creator;

    public B(A creator) {
        this.creator = creator;
    }

    public void action() {
        //stuff
    }

    public void main(String[] args) {

        while(true)
            if(something==true) {
                creator.signal();
            }

   }
}
  • 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-06T11:00:54+00:00Added an answer on June 6, 2026 at 11:00 am

    Give them both access to the same Queue. One puts elements onto it, the other pulls elements from it. If they’re in separate threads, one of the BlockingQueue implementations should do the trick.

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

Sidebar

Related Questions

Not really sure how to phrase this other than by example.. Given... DATABASES =
I am really new to SWIG. I tried to compile the example given in
I'm really new to programming... I set up a class to give supporting information
This is probably a really silly question but, given the example code at the
Given this really simple Wicket component: public class ProductImage extends WebComponent { public ProductImage(String
Here's a really simple question regarding pythonic coding. Given a list, if you want
I really don't know enough about regex to tackle this on my own so...
I've been given the task of re-engineering a really old VB3 application. As part
Given a really large, 3+ gig, binary file is there anyway that I could
I've been using delegates for many years, and haven't really given them much thought.

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.