Objects communicating with each other

Suppose I have a main class that has a Thread instance variable. What is the best way to notify the main class that something has happened in the thread?
Example:
I have a main class, a Producer, and a Consumer. Both the Producer and the Consumer extend Thread.
The main class is supposed to keep track of when the Producer produces something, and when a Consumer consumes something.
What is the best way for the Producer/Consumer to tell the main class that something has been produced/consumed?

example of Vistor parttern from Wikipedia
interface Visitor {
    void visit(Wheel wheel);
    void visit(Engine engine);
    void visit(Body body);
    void visitCar(Car car);
    void visitVehicle(Vehicle vehicle);
class Wheel {
    private String name;
    Wheel(String name) {
        this.name = name;
    String getName() {
        return this.name;
    public void accept(Visitor visitor) {
        visitor.visit(this);
class Engine {
    public void accept(Visitor visitor) {
        visitor.visit(this);
class Body {
    public void accept(Visitor visitor) {
        visitor.visit(this);
abstract class Vehicle {
    protected Engine  engine = new Engine();
    protected Body    body   = new Body();
    protected Wheel[] wheels;
    public Engine getEngine() {
        return this.engine;
    public Body getBody() {
        return this.body;
    public Wheel[] getWheels() {
        return this.wheels;
    public void accept(Visitor visitor) {
        visitor.visitVehicle(this);
class Car extends Vehicle {
    public Car() {
        super();
        this.wheels = new Wheel[]
          { new Wheel("front left"), new Wheel("front right"),
            new Wheel("back left") , new Wheel("back right")  };
    public void accept(Visitor visitor) {
         visitor.visitCar(this);
class PrintVisitor implements Visitor {
    public void visit(Wheel wheel) {
        System.out.println("Visiting "+ wheel.getName()
                            + " wheel");
    public void visit(Engine engine) {
        System.out.println("Visiting engine");
    public void visit(Body body) {
        System.out.println("Visiting body");
    public void visitVehicle(Vehicle vehicle) {
        System.out.println("Visiting vehicle");
    public void visitCar(Car car) {
        System.out.println("Visiting car");
        car.getEngine().accept(this);
        car.getBody().accept(this);
        for(Wheel wheel : car.getWheels()) {
            wheel.accept(this);
class DoVisitor implements Visitor {
    public void visit(Wheel wheel) {
        System.out.println("Steering my wheel");
    public void visit(Engine engine) {
        System.out.println("Starting my engine");
    public void visit(Body body) {
        System.out.println("Moving my body");
    public void visitCar(Car car) {
        System.out.println("Starting my car");
        car.getEngine().accept(this);
        car.getBody().accept(this);
        for(Wheel wheel : car.getWheels()) {
            wheel.accept(this);
    public void visitVehicle(Vehicle vehicle) {
        System.out.println("Starting my vehicle");
public class VisitorDemo {
    static public void main(String[] args){
        Car car = new Car();
        Visitor printVisitor = new PrintVisitor();
        Visitor doVisitor = new DoVisitor();
        car.accept(printVisitor);
        car.accept(doVisitor);
}

Similar Messages

  • VM Machines not communicating with each other on Hyper-V 2012

    In Hyper-V 2012 on Server 2012 I have created two VM's Server 2008 64-bit & Server 2012 64-bit.
    The problem is both VM's are not communicating with each other.
    Regards
    Ganesh Parte

    Hello,
    seems this belongs to the Hyper-V networking configuration settings. Please ask this in http://social.technet.microsoft.com/Forums/en-US/home?forum=winserverhyperv
    and also describe how you have the network settings configured in the Hyper-V MMC.
    Best regards
    Meinolf Weber
    MVP, MCP, MCTS
    Microsoft MVP - Directory Services
    My Blog: http://blogs.msmvps.com/MWeber
    Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.
    Twitter:  

  • BODS / SAP : what set-ups are required for communicating with each other ?

    Hi.
    There is a new SAP system
    And there is a new BODS installation.
    Both on independent server machines but on the same lan network.
    On the test system of BODS. We tried to see how the communication happens with SAP.
    While we try some test jobs by trying to pull a simple table on SAP R/3
    In Dataflow, we used simple SAPR/3 ABAP flow. And put it into target database thro query transformation.
    In the datastore,
    We used the Generate and Execute option,
    with a path on the local directory of BODS server for creating the ABAP program and the dat file.
    However,
    We are always getting error on batch job schedule.
    Although the user is having rights on the R/3 table
    And can login into SAP R/3 system and check the table.
    Still we get an error saying Databstore unabel to connect to R/3 system. Check for user login etc.
    For anyone whose login we use. We get the error.
    However, if i directly generate the code on the ABAP flow (without running the job),
    make the program available on R/3 system.
    and then run the job as execute preloaded
    this works fine without any error.
    and we are able to see the data in the target table.
    Now both the systems are new.
    And am not aware of the initial set-ups which are required for communication between SAP / BODS.
    Are WE missing something on the SAP side setups - for generate and execute option to be used?
    Is there anything specific to be done for ease of the communication between SAP server and BODS server in this regard.
    Can anyone share some inputs on this.
    Actually for any user with full admin rights too, on the sap side, if we use the user login for R/3 connectivity for this particular "generate and execute" option,  it errors out after nearly 10 minutes. Then the error says, login info not correct.
    So basically, the communication channel by itself between SAP R/3 and BODS seems to be locked somewhere.
    If anyone with SAP admin expertise - can help or advise on this.
    Many thanks
    Indu
    Edited by: Indumathy Narayanan on Sep 13, 2011 9:20 PM

    Getting data out of R/3 requires two distinct setup tasks, and they don't have much to do with each other.
    The first basic task is to get the little ABAP extraction programs loaded and run in R/3.  You can pre-load them and then call them, or generate, upload, and execute them all on-the-fly, at BODS runtime.  During development, use "Generate and Execute" for your ABAP.
    Once that's done, you have four different choices to get the data back: "Direct download", "Shared directory", FTP, and "Customer Transfer". Normally, you'll use either FTP or "Shared directory".  Refer to the documentation (the BODS SAP Supplement) for a description of all this.
    In all cases (or at least, quite certainly, using the FTP and Shared Directory methods), the ABAP extraction programs are directed to plop their output as flat files in the "Working directory on SAP server."  For testing, you can look in that folder to see if any flat files are appearing when you submit an ABAP data flow.  If not, then either 1) your ABAP program isn't getting in there (a Basis admin should be able to tell you), or 2) it's not running (ditto), or 3) it's running but unable to generate the output file (ditto), because a) SAP isn't permitted to write to that folder, or b) the folder doesn't exist (it needs to be defined from the perspective of the SAP server).
    If you do see files appear in the "Working directory on SAP server" when you run a BODS job w/ an ABAP dataflow, then the problem is that BODS can't fetch them.  If you're using the "Shared directory" method, which is suitable for and often used in all-Windows environments, then the account under which the Job Server in question is running must have access to the "Working directory on SAP server," but this time from the perspective of the Job Server.  So if, for instance, SAP was directed to put the flat files on a local folder, say, "E:\USR\SAP\BODS", then you might want to share this folder out as, for instance,
    sapdev1\bods (for an SAP host called "sapdev1"), and then enter "
    sapdev1\bods" in the "Application path to shared directory" field, in your SAP datastore configuration.  If your Job Server service is logging-in as "Local System," though, it won't be able to get there -- it needs to log-in as an AD domain account w/ rights to that share.  Get it?  Try logging in to your BODS job server computer with the AD "service account" setup for use by the Job Server service, and try to open a file on the "Application path to shared directory". If you can't, then BODS won't be able to get data from ECC, either.  FTP works similarly -- if you're using that and having trouble, please re-post.
    Best wishes,
    Jeff Prenevost
    Data Services Practice Manager
    itelligence

  • Two ear file communicating with each other

    HI,
    I have one doubt,
    I Have two ear files (two webservices actually) deployed succesfully in the same application server (Weblogic7.0). Let us say them a.ear and b.ear
    In a.ear there are class say A.class and B.class. In B.java file there is a staic HashMap which stores some object based on some id. Also in B.java there is static method which takes the id as a parameter and return the corrospojnding object stored in the static hasmap.
    In b.ear file there class say B.class and C.class. Note that this ear file has its own copy of B.class file. In C.java file i create an object (though i dont need create being it a static method) of B.java and calls the static object passing it the id and expecting it that it will return me the object stored in the Hashmap. it returns me null though it has the objects stored for that id.
    Is it because both ear files has their own copy of B.class. but i though that that they are running in the same jvm in application server so it should not be a problem. if this is the reason then my problem will be solved if i put them in same ear file.
    Can anybody put his insights into his experiences and lemme know what is the cause of problem and solution and for my knowledge why it is happening.
    Best Regards,
    Akhil Nagpal

    You're right that the two have different copies of the class. This is because the EJB container uses a different classloader for different applications, to prevent statics clashing with each other and other related security reasons.
    Usually if you want to communicate from one to the other, you would use the EJB mechanism itself. The JNDI names should be global (from simple tests I did in the past, this seems to be the case) so that one application can look up an EJB from the other.

  • 2 AIR applications directly communicating with each other in real time

    Building a installation that requires 2 different kiosks to communicate with each other. I'd like to use Adobe AIR to create the individual applications.
    My question is
    Is it possible for 2 separate AIR applications to DIRECTLY communicate with each other in real time, without any server to act as mediator?
    Ideally the only data that would be transferred would be json based.

    Not sure whether this helps; http://www.adobe.com/devnet/air/flex/articles/creating_socket_server.html

  • How can I have threads communicate with each other?

    I'm working on a project that requires a group of classes communicating with each other. I decided on using a server and carrying out communication that way. However, my app only has communication between the client and server. I need the clients to be able to communicate with each other. Does anyone know how I can do this or point me to a good tutorial?

    Sorry, here's a bone stock example of my server and client:
    <SERVER>
    package testserver;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class TestServer
    static int portOpen;
    public static void main(String[] args)
    portOpen=4000;
    try
    ServerSocket portListener = new ServerSocket(portOpen);
    TestServer userThreads = new TestServer();
    while (1==1)
    Socket userConnection=portListener.accept();
    userThreads.new PortConnection(userConnection);
    catch (Exception e)
    System.out.println("The server encountered a serious error. Server shut down.");
    e.printStackTrace();
    System.exit(0);
    class PortConnection extends Thread
    //Declare variables to handle connections.
    Socket ourConnection;
    BufferedReader serverInput;
    PrintWriter serverOutput;
    PortConnection(Socket userConnection)
    try
    ourConnection=userConnection;
    serverInput=new BufferedReader(new InputStreamReader(userConnection.getInputStream()));
    serverOutput=new PrintWriter(userConnection.getOutputStream(),true);
    start();
    catch (Exception e)
    System.out.println("An error occurred when a user attempted a connection.");
    public void run()
    serverOutput.println("Welcome to the Server.");
    try
    serverOutput.close();
    serverInput.close();
    ourConnection.close();
    catch (Exception e)
    </SERVER>
    <CLIENT>
    package testclient;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    public class TestClient {
    static BufferedReader userInput;
    static Socket quizServer;
    static BufferedReader serverInput;
    static PrintWriter serverOutput;
    static String serverData;
    public static void main(String[] args) {
    userInput = new BufferedReader(new InputStreamReader(System.in));
    try {
    quizServer=new Socket("localhost",4000);
    catch (Exception e) {}
    try
    serverInput=new BufferedReader(new InputStreamReader(quizServer.getInputStream()));
    serverOutput=new PrintWriter(quizServer.getOutputStream(),true);
    catch (Exception e) {}
    try {
    serverData=serverInput.readLine();
    catch (Exception e) {}
    System.out.println(serverData);
    </CLIENT>

  • Migration between two environments which can't communicate with each other

    My customer is intending to do migration from test environment to production environment using CCM.
    But the two environments are not in the same network.
    The environments' setting is as blew.
    BO TEST Repository can communicate with Web BO Server.
    BO PRODUCTION Repository (Cluster environment) can communicate with Web BO Server.
    BO TEST Repository and BO PRODUCTION Repository (Cluster environment) are in the different network, they can't communicate with each other.
    Setting Target Repository manually in CCM.
    Questions are:
    1. In CCM, as long as both Source Repository and Target Repository can communicate with Web BO Server, the migration will be successful.
       Is that right?
    2. If 1 is not right, is there additional setting should I do?
       For example, If I need to open some firewall port?
    3. Is there other attentions should I notice?
    Thanks

    Questions are:
    1. In CCM, as long as both Source Repository and Target Repository can communicate with Web BO Server, the migration will be successful.
    Is that right?
    Yes that is correct
    2. If 1 is not right, is there additional setting should I do?
    For example, If I need to open some firewall port?
    You have another option which is to use the BIAR files. Export your objects to a BIAR file in source environment, and import them from BIAR into the target environment
    3. Is there other attentions should I notice?
    when using BIAR files as solution, Make sure that you keep them < 1GB size to avoid corruption
    you may have to increase or adjust timeouts on input and output repository servers as well

  • Premiere Pro CS5 confuses images with each other

    Hi Adobe-Community,
    I've got a severe problem, that is holding back my whole project at the moment, and I really hope you can help me with this.
    Premiere regularly confuses the images I have added to my project with each other. So when I am importing 2 images, let's say CIMG5967.JPG and CIMG5974.JPG, by dragging them into my project, two new elements are created. But when I'm putting these elements into my sequence, both appear as the same image, although they are still properly named after their original file.
    Sometimes the very same problem even occurs some days later, so parts of my project, that have already been finished, suddenly appear as if I would have used the same image over and over again.
    I'm using Adobe Premiere Pro CS5 - Version 5.0.3
    Using the option to clean up the media-cache-db didn't help.

    Happened to me once - a corrupt project.
    Unlink all the faulty images. 
    Open a new project. 
    IMPORT the old project
    Relink the images.

  • How do I enable two wireless clients to communicate with each other?

    I have a WRT54GL with the latest firmware.  I have two computers which are both connected to the router, with IP addresses assigned via DHCP.  Neither has a firewall running.  I cannot get them to communicate with each other -- even ping doesn't work.  I can ping the router itself using the IP address assigned to it on the WAN side by my ISP.   Both computers have no problem reaching the internet through the router.
    What settings on the router will enable the communication to occur?  I can't find anything in the router's user interface which appears to control this. 
    Thanks.
    Solved!
    Go to Solution.

    Hi annie25,
    I think it would be best to check on netgear or belkin technical forums how to make these two talk. 
    Yesterday is history. Tomorrow is mystery. Today is a gift.

  • HT5225 I have an imac 24 , imac 27, mac book pro, airbook and Iphone 3G.  I have switched to icloud from mobile and all the computers synch with each other but data entered from my iphone in ical won't sync to the other computers.

    I have an imac 24 , imac 27, mac book pro, airbook and Iphone 3G.  I have switched to icloud from mobile and all the computers synch with each other but data entered from my iphone in ical won't sync to the other computers.
    Is there a setting on the iphone that will allow ical entries on the iphone to sink to my other computers
    Thank-you

    Welcome to the Apple community.
    First check that all your settings are correct, that calendar syncing is checked on all devices (system preferences > iCloud on a mac and settings > iCloud on a iPhone, iPad or iPod).
    Make sure the calendars you are using are in your 'iCloud' account and not an 'On My Mac', 'On My Phone' or other non iCloud account (you can do this by clicking/tapping the calendar button in the top left corner of the application ), non iCloud calendars will not sync.
    If you are sure that everything is set up correctly and your calendars are in the iCloud account, you might try unchecking calendar syncing in the iCloud settings, restarting your device and then re-enabling calendar syncing settings.

  • Why instanses randomly exchanging colors with each others.

    I have a trouble with Instances of movieclip loaded by AS3
    script.
    After adding 5 of them in scene I trying to change colors of
    them by using colorTransform. And it's works fine.
    But after that I change x,y coordinates of them in loop.
    Kinda moving... And, instances start to swap their colors with each
    other at some point of their way. I traced color offsets for
    specified MC, and in numbers it's doesn't change they're colors. It
    seams like flash itself, when rendering, think that this objects
    are the same, and draw them like he wants. How to avoid this? Even
    changing colors in "moving" loop doesn't help.

    Up! need help!
    Examples:
    Multishapes - 30 shapes on rail differently colored
    exchanging colors with eachother:
    http://exp.yaoiportal.com/multishape.swf
    3 shapes where only one have unique color. Here you can
    clearly see whats going on:
    http://exp.yaoiportal.com/3shape.swf

  • TS3988 I have set up all the iCloud on my iPad and iPhone both are the latest version but they don't seem to sinc with each other does this take some time? I am connected to the Internet via wifi do I need to turn the mobile data to on on both maybe??

    I have set up all the iCloud on my iPad and iPhone both are the latest version but they don't seem to sinc with each other does this take some time? I am connected to the Internet via wifi do I need to turn the mobile data to on on both maybe??

    Welcome to the Apple Community.
    You need to turn the services you want to sync (calendars, contacts etc) on on both devices from settings > iCloud.

  • How do I Help Apple Care Stop Warring with Each Other and Fix the Problem with My iPhone that They Acknowledge Creating?

    How Do I Help Apple US & Apple Europe Stop Warring With Each Other And Fix The Problem They Created?
    PROBLEM
    Apple will not replace, as promised, the iPhone 5 (A1429 GSM model) that they gave me in London, UK, with an iPhone 5 (A1429 CDMA model).
    BACKGROUND
    My iPhone 5 (A1429 CDMA model) was purchased this year in September on an existing Verizon Wireless (VZW) line using an upgrade. The purchase took place in California and the product was picked up using Apple Personal Pickup through the Cerritos Apple Retail Store. I will refer to this phone at my "original" phone.
    The original phone was taken into the Apple Store Regent Street in London, England, UK on November 15, 2012. The reason for this visit was that my original phone's camera would not focus.
    The Apple Store Regent Street verified there was a hardware problem but was unable to replace the part.
    The Apple Store Regent Street had me call the US AppleCare. At first they denied support, but then a supervisor, name can be provided upon request, approved the replacement of my original phone with an iPhone 5 (A1429 GSM model) as a temporary solution until I got back in the US. And approved that the GSM model would be replaced with a CDMA model when I came back to the US. I will refer to the GSM model as the "replacement". They gave me the case number --------.
    The Apple Store Regent Street gave me the replacement and took the original. The first replacement did not work for reasons I do not understand. They switched out the replacement several times until they got one that worked on the T-Mobile nano SIM card that I had purchased in England, UK. Please refer to the repair IDs below to track the progression of phones given to me at the Apple Store Regent Street:
    Repair ID ----------- (Nov 15)
    Repair ID ----------- (Nov 16)
    Repair ID ----------- (Nov 16)
    The following case number was either created in the UK or France between November 15 to November 24. Case number -----------
    On November 19, 2012, I went to France and purchased an Orange nano SIM card. The phone would not activate like the first two repair IDs above.
    On November 24, 2012, I went to the Apple Store Les Quatre Temps. The Genius told me that my CDMA phone should not have been replaced with a GSM model in the UK and that this was clearly Apple's fault. They had me call the AppleCare UK.
    My issue was escalated to a tier 2 UK AppleCare agent. His contact information can be provided upon request. He gave me the case number -----------.
    The UK tier 2 agent became upset when he heard that I was calling from France and that the France Apple Store or France AppleCare were not helping me. He told me that my CDMA phone should not have been replaced with a GSM model in the UK and that this was clearly Apple's fault.
    The UK tier 2 agent said he was working with engineers to resolve my problem and would call me back the next day on November 25, 2012.
    While at the Apple Store Les Quatre Temps, a Genius switched the phone given to from repair ID ----------- with a new one that worked with the French nano SIM card.
    Also, while at the Apple Store Les Quatre Temps, I initiated a call with AppleCare US to get assistance because it seems that AppleCare UK was more upset that France was not addressing the issue rather than helping me. I have email correspondance with the AppleCare US representative.
    A Genius at the Apple Store Les Quatre Temps switched the replacement with a new GSM model that worked on the French SIM card but would not work if restored, received a software update, or had the SIM card changed. This is the same temporary solution I received from the Apple Store Regent Street in the UK.
    By this point, I had spent between 12-14 hours in Apple Store or on the phone with an AppleCare representative.
    Upon arriving in the US, I went to my local Apple Store Brea Mall to have the replacement switched with a CDMA model. They could not support me. He told me that my CDMA phone should not have been replaced with a GSM model in the UK and that this was clearly Apple's fault. My instructions were to call AppleCare US again.
    My call with AppleCare US was escalated to a Senior Advisor, name can be provided upon request, and they gave me the case number -----------. After being on the phone with him for over an hour, his instructions were to call the Apple Store Regent Street and tell them to review my latest notes. They were to process a refund for a full retail priced iPhone 5 64BG black onto my credit card so that I could use that money to buy a new iPhone 5 64GB black at the Apple Store Brea Mall to reoslve the problem.
    The Apple Store Regent Street did not process my refund. He, name can be provided upon request, told me that the AppleCare US did not do a good job reviewing my case, that they were incapable of getting to the bottom of it like they were, and instructed me to call AppleCare US and tell them to review this case number and this repair id. I asked if he read the notes from the AppleCare US Senior Advisor and he would not confirm nor deny. When I offered to give him the case number he accepted but it seemed like would do no good. Our call was disconnected. When I tried calling back the stores automated system was turned on and I could not get back through.
    Now I have the full retail price of an iPhone 5 64GB black CDMA on my credit card and Apple will not process the refund as they said they would.
    I've, at this point, spent between 14-16 hours at Apple Stores or on the phone with AppleCare representatives, and still do not have the problem resolved.
    SOLUTION
    AppleCare US and AppleCare Europe need to resolve their internal family issues without further impacting their customers.
    Apple is to process a refund to my credit card for the cost of a full retail priced iPhone 5 64GB black.
    DESIRED OUTCOMES
    I have an iPhone 5 (A1429 CDMA model) that works in the US on VZW as it did before I received the replacement phone in the UK.
    Apple covers the cost of the solution because I did not create the problem.
    Apple resolves their internal issue without costing me more time, energy, or money.
    This becomes a case study for AppleCare so that future customers are not impacted like I have been by their support system.
    Does anyone have recommendations for me?
    Thank you!
    <Edited by Host>

    Thanks, but I've been on the phone with AppleCare US (where I am and live) and AppleCare UK. They continue bouncing me back and forth without helping resolve the problem.
    Perhaps someones knows how to further escalate the issue at Apple?

  • Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help..

    Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help.

    HI, if I did this, then I believe that I cloud would then hold my info which I don't want. Is that the case? The reason is that I'm an old git, therefore used to not giving out info. Would I be right?
    Thank-You so much for taking the time to answer.
    John.

  • I currently use an iPhone, an iPad, and a Mac computer for business.  The three devices have Contacts Managers that sync with each other through both Google and through Mobile Me.  Currently, this has created a mess of duplicate contacts.  Please researc

    I currently use an iPhone, an iPad, and a Mac computer for business.  The three devices have Contacts Managers that sync with each other through both Google and through Mobile Me.  Currently, this has created a mess of duplicate contacts.  Please advise me on the steps necessary for removing these duplicates and establishing a syncing solution that doesn't regenerate the duplicates.  There are several applications available that remove duplicates, but I am not sure which ones work or don't work.  I want information on this, but most importantly I want to understand how to fix this problem permanently.  Also, I read somewhere that Mac's new operating system, Lion, can help deal with duplicates.  I don't have Lion, but I would be willing to get it, if this would fix the problem.

    Had the same problem with 4 devices (two computers, an iPhone and an iPod). The solution is simple: open the Address Book application in your mac, ask it to locate duplicate entries (under one of the top menu items, "edit" I think), and then ask it to consolidate them: it took me all of three seconds after I figured it out: worked like a charm! PS: if you have more than one mac with unconected Address Books, repeating the operation in the second one may be a good idea.
    Message was edited by: mfduran

Maybe you are looking for