Synchronizing objects between classes?

so, i ought to know this, but i've never done this in my classes before, so here goes:
I have an object, call it object A, that i create in a class, call it class B.
i then pass object A to 2 other classes, class C and class D.
the object is then changed in class C. Is it possible to detect that change in class D without passing a new copy of the object?
it seems to me like it should be, and the actual data that changes is another object inside object A, so does that complicate matters?
when i run test code it works, but it's not working in production.
the code is way too long to post here.
any ideas? i REALLY appreciate your time in considering this problem.

ok, so i figured it out.
finally i got the correct name of it: shallow and deep copying, after some googling it LOOKED like i was doing it right and yet my example code still said no.
then i rethought my example, and realized that i was making a certain assumption that, in the end, was not actually true in that case.
once i reversed that assumption, i realized that the code is working perfectly.
thanks for the help.

Similar Messages

  • Difference Between Business Object And Class Object

    Hi all,
    Can any one tel me the difference between business object and class Object....
    Thanks...
    ..Ashish

    Hello Ashish
    A business object is a sematic term whereas a class (object) is a technical term.
    Business objects are all important objects within R/3 e.g. sales order, customer, invoice, etc.
    The business objects are defined in the BOR (transaction SWO1). The have so-called "methods" like
    BusinessObject.Create
    BusinessObject.GetDetail
    BusinessObject.Change
    which are implemented (usually) by BAPIs, e.g.:
    Business Object = User
    User.Create => BAPI_USER_CREATE1
    User.GetDetail => BAPI_USER_GET_DETAIL
    CONCLUSION: Business Object >< Class (Object)
    Regards
      Uwe

  • Is there any Similar between Class.forName() and new operator ???

    Plz tel me is there any Similar between Class.forName() and new operator ??? i have been asked this ques in interview

    You probably should have used the other thread:
    http://forum.java.sun.com/thread.jspa?threadID=792678
    To add a little confusion to the matter...Class objects are in fact objects. They're objects representing classes. So, in a sense, I guess, you could say they're similar -- in each you get an object. But in practice Class objects and all other objects should be considered semantically different unless you're doing some pretty unusual stuff. Also Class.forName is more of a factory method than a constructor.

  • Sharing an object between other objects?

    I have two classes, say DisplayPanel and ControlPanel. Both of these classes need to have access to a single instance of an object of type Data, say theData. I want to be able to set theData to a new object at any time, for example, theData = new KindOfData().
    If I store a reference to theData in both objects, when I set theData to a new object in one class, the other will still reference the old object. Is there a way to share an object between two classes as I described?
    I could create a superclass for DisplayPanel and ControlPanel that contains an instance of Data, however I may need to access this object in other classes and do not want to have the inflexibility of having to extend a possibly unrelated class just to access a single data member.
    Is there any easy way to go about this? Thanks for your help.

    Create a listener interface. Make each class implement that interface. When you create each class, register it as a listener to theData. Keep track of all listeners in a List such as an ArrayList. When you want to change theData, iterate through the List and call the interface's method to update theData in each class:
    public interface SomeListener
       void updateData(KindOfData theData);
    public class DisplayPanel implements SomeListener
      private KindOfData theData;
      public void updateData(KindOfData newData)
         theData = newData;
    public class SomeOtherClass
       private List listenerList = new ArrayList();
       public void addDataListener(SomeListener listener)
            listenerList.add(listener);
       public void fireDataChange(KindOfData newData)
           for (Iterator listenerIter = listenerList.iterator();
                  listenerIter.hasNext();
               ((DataListener)listenerIter.next()).updateData(newData);
    }Look at how EventListeners are added and fired in Swing classes.

  • (UIX XML) Sharing Connection objects between BC4J and custom java.

    If I have a UIX XML page that contains some BC4J application modules, then in the event handler I call [public static EventResult handleMyEventEvent (BajaContext context, Page page, PageEvent event..) ], which in turn calls some java classes I have written that take a java.sql.Connection object and access the database doing some updates/inserts with this Connection object (via JDBC)....HOW CAN I USE THE SAME TRANSACTION AS WAS USED IN THE BC4J APPLICATION MODULE...i.e. CAN I SHARE THE CONNECTION OBJECT BETWEEN BC4J AND MY OWN JAVA CLASSES THAT USE JDBC?
    What are the best ways to share such a transaction?
    Thanks,
    Paul.

    Would it be easier to use a custom method on the bc4j Application module?
    Take this scenario...
    1. User opens UIX XML web page which opens a bc4j App Module..it has a VO based on all employees.
    2. User presses the add button and a new employee is created (using the bc4j App Module).
    (Notice: no commit yet!)
    3. User presses the submit button...fires event REVIEW_SALARY.
    4. This event is 'handled' in the event section of the UML XML...it calls:-
    public static EventResult handleREVIEW_SALARYEvent (BajaContext context, Page page, PageEvent event)...
    5. I now want to call a java class I wrote that computes an employees new salary and updates the employee record with this new salary. This update will fail unless it is part of the same transaction as the one used by the bc4j App Module (that inserted the new employee).
    How best to proceed from here?
    How about having a method on the bc4j App Mod's VO called 'reviewSalary'? Calling this would use the same transaction? I could then call my java class from within the VO's method? However do I still have the same problem in that my java class expects to be passed the connection object?
    The approach you suggested previously seems a touch dangerous....in that these are not 'publically exposed'...and a new release of JDev may break my code.
    Thanks,
    Paul.

  • Lifetime of JNI objects between calls.

    Is it possible to store/cache non-class JNI objects between calls?
    I know I can 'lock' jclass object to *env however I need to be able to do more than this.
    Implementation :
    C++ code for which I am not responsible for NOR will I ever get access to the source code needs to be built into a Java Application.
    Everything that I need to do works fine except when I need to have jobject's and, in particular, the JNIEnv reference to be cached in the dll between JNI calls.
    Raison d'etre : I want to implement a Callback using a Java object (Observer/Observable) so that the status of the C legacy app can be monitored via a callback implemented as part of the dll.
    Java object is called via the C callback, sets status via a status method called via JNI, Java App is notifoed of the change.
    Problem, as long as the first call the the jobject occurs within the actual JNI call that creates the Java object all is well, as soon as I try and store the jobject and JNIEnv references so that the C callback can call it as well then things break.
    Is it possible to have JNI objects whose lifetime spans JNI calls at all?

    In the meantime I have found out exactly how to achieve callbacks via native/Java. Having studied Sheng Liang's book (an absolute must buy and read) things became a lot clearer.
    This is what I discovered...
    The main issues with implementing callbacks within a JNI framework are the following..
    Lifetime of the JNIEnv and other classes/objects involved on the native side of the process.
    Threading issues on the native side, especially when interacting with Objects created in a different thread.
    The first issue is dealt with, in part, by being able to obtain a valid JNIEnv at arbitrary points in the native code. If you obtain a valid JNIEnv in an arbitrary native thread that JNIEnv is valid in it so this also helps problems with the second issue.
    The key to obtaining a valid JNIEnv is in having a reference to the calling VM.
    The function..
    JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
    allows you to cache a reference to the calling JVM. It is called when the dll is loaded before any other functions in the native code are called. The JavaVM reference is valid throughout the lifetime of the dll's instance.
    you can then do this to obtain a valid JNIEnv anytime you like..
    JNIEnv *env;
    vm->GetEnv((void **)&env, JNI_VERSION_1_2);
    Ok, thats dealt with problem of obtaining valid JNIEnv's when we need them.
    In order to extend the lifetime of objects and, in particular, classes from which those objects are instantiated you need to create global ref's to them. I did mine this way..
    In the calling Java code, I instantiate a callback object and pass that to a native method whose native code does the following..
    gets the object's class as a local reference, creates a NewGlobalRef of the passed object and its class. These jobject and jclass global references are stored as global vars in the DLL. You can also, at this point, create jmethodID's for all the methods you may need to call as part of the callback process however callbacks should finish as quickly as possible so restrict your calls to the minimum. Caching the method ID does not require a global ref, nor is is thread 'sensitive'. GetMethodID can be used to store a local jmethodID reference in a global jmethodID var, this saves you some time and performance hits in the native callback functions.
    The above description deals with the lifetime of objects between JNI calls. What about the threading issues?
    We have seen how to get a valid JNIEnv when we want one. This JNIEnv is valid for the NATIVE thread in which we call vm->GetEnv((void **)&env, JNI_VERSION_1_2);
    There is another way of getting valid JNIEnv's when we want them but this seems only to work when we are using the invocation interface (having the native side create an embedded JVM). This is the jvm->AttachCurrentThread function. I have tried both, only GetEnv seems to work as expected in the native DLL code, AttachCurrentThread when the JVM is invoked from inside a native application.
    To successfully perform the native/Java callback, assuming you have cached a JavaVM reference and the callback object/class correctly, is to get a valid JNIEnv as shown above, use this JNIEnv for the method calls you need to perform on the callback object, cleanup if needed.
    Note, you MUST DeleteGlobalRef's before the DLL is unloaded. If you don't you may find your Java VM crashing on exit (a horrible bug to have to track down).
    Either explicitly create a cleanup native method that you have to call and/or use the JNI_OnUnload function that is called just before the DLL is unloaded (usually when the JVM is being stopped).
    Things you can do to make your callback efficient :
    Make the calls return as soon as possible. I use the Observable/Observer pattern so that further Java objects (the observers) can handle the changes made to the callback object. If, like me, you are reflecting state changes in the native system component via callbacks and displaying them in a GUI environment then your Observer can wake up a thread to do the GUI updates, the observable callback need only notifyObservers in order to start things off and return.
    Hope this clears things up for you, if you have further questions please mail me, I believe my email address is available, if not post here and I will get to you.

  • Questions on scripts, tables & transfer objects between clients.

    1. In script, how to use the same print program for two different layouts? with procedure.!
    2. Why cant sapscripts be client independent.?
    3. Want to maintain a table in dev server and if i update the data, it should simultanously update in Quality and Production servers. How? please explain in details.
    4. How to transfer object between clients.? explain.
    Points will be promptly rewarded for HELPFULL answers.!

    Hi!
    3. With SE01, you can create a transport request for all table entries.
    SE01 - Create button - Workbench request - Give description and save
    Select the created request and click on Display object list.
    Click on Display - Change button
    Insert line button
    ProgID: R3TR
    Object: TABU
    Object name: Z_YOUR_TABLE
    Double click on the table name
    Insert line
    Key: *
    Save everything
    Release the transport in SE10 transaction and transport with STMS transaction.
    Regards
    Tamá

  • Custom Events and Listeners between classes

    I've got a project I've been working on for weeks that I'm
    having yet another problem with. I'm trying to learn AS3 which is
    why it's taking so long but that's not important for this post.
    I wanted to create a custom event class so that I could make
    sure the event does not interfere with other "COMPLETE" events that
    are being passed between classes. In other words, I have a few
    things that need to complete prior to a function being called...
    one is some XML being loaded and another is a font loaded. So, I
    thought I would create a custom FontLoaded class that extends Event
    and make the type something like "FontLoadedEvent.LOADED". That way
    I could listen for the XML "Event.COMPLETE" and this font event
    also.
    Please tell me if I'm going down the wrong path here but I
    don't seem to be getting the dispatched event for my new custom
    event. Also, how does one detect if it's being dispatched other
    than if the eventListener is fired? Any other ways to test
    this?

    You can trace the event to see if it dispatched.
    Also, this is not a good case to create a new event. Custom
    events are used to store additional information. MouseEvent exists
    because Event doesn't have localX, localY, etc. properties. Since
    you don't seem to be throwing additional properties, you can use a
    regular event.
    trace(dispatchEvent(new Event("panelFontsLoaded"));
    addEventListener("panelFontsLoaded", onFontsLoaded);
    Static consts are used to help debug typos. The event type is
    just a string, often stored in a const.

  • Creation of Module - Object of class Channel

    Hi everybody,
    I neeed to create an adapter module in which I have to create an object of class Channel.
    This object Channel belong to the package com.sap.aii.mapping.lookup
    I need to know in which jar it is.
    We are in PI 7.1.
    Can somebody help me, please?
    Thank in advance for your collaboration.
    Best Regards.
    E. Koralewski

    Hi Eric,
    >>>>>>>>>I neeed to create an adapter module in which I have to create an object of class Channel.This object Channel belong to the package com.sap.aii.mapping.lookup I need to know in which jar it is.  We are in PI 7.1.
    Please see what is you look for.        
    com.sap.xpi.ib.mapping.lib.jar
    Regards,
    Rajesh
    Edited by: Rajesh_1113 on Feb 2, 2011 4:16 PM

  • How to create unique objects in class and store

    Hi, I have a class that opens a text file and reads in the
    lines. each line holds an ip address. i need to create x amount of
    objects, and each object is assigned a unique ip address from the file.
    and here i am stuck. the class reads in the file, then i think it should create an object for each line read in and assign that object the ip address. i want to store the objects in some sort of array or collection, and i guess each object will need a unique name, but i dont know how many objects until i read in the file and count the number of lines. can anyone give me any pointers as to how i should create/store the objects
    many thanx
    ness

    You could use your own object:
    public class Test {
      public class IPNumber {
        public int ip;
        public IPNumber(int ip) {
          this.ip = ip;
      public Test() {
        int numberOfIPs = 5; // this is your number of lines
        IPNumber[] ips = new IPNumber[numberOfIPs];
        for (int i = 0; i < numberOfIPs; i++) ips[i] = new IPNumber(i); // assign ip address from file
      public static void main(String args[]){
        new Test();
    }or you could store the ips as strings:
    public class Test {
      public Test() {
        final int numberOfIPs = 5; // this is your number of lines
        final java.util.ArrayList al = new java.util.ArrayList(numberOfIPs);
        for (int i = 0; i < numberOfIPs; i++) al.add(""+i); // assign ip address from file   
      public static void main(String args[]){
        new Test();
    }p.s Objects don't have names

  • Synchronous Communication between two Decoupled Orchestration

    Hi All,
    Is there a way I can achieve synchronous communication between 2 orchestrations (decoupled orchestrations) where I need to pass multiple parameters from calling orchestration to called orchestration.
    Thanks,
    Sumit
    Sumit Verma - MCTS BizTalk 2006/2010 - Please indicate "Mark as Answer" or "Mark as Helpful" if this post has answered the question

    Hi Sumit,
    if you have hundreds of orchestration means lot of small small business processes which are tightly coupled...
    It is better to publish process / orchestration as service so it will  SOA base ..it will work isolate. but remember if you publish more web base service. it will be burden on IIS. we have only one Host instance to handle..we can't create more host
    instance to handle like in-process host in one server..we have to go for cluster environment..so first approach will be window base service (if possible achieve business process ) to handle by in-process host instance.
    If you have many small small services then we need one master service to watch/process all the services.
    Exmaple...
    Like one process A, need to execute five small services/processes a1,b1,a2,c1,c3
    and Process B need to execute four small services/processes b1,b2,a1,c1
    You have to go for canonical schema and master entry table where you can dynamically change or attached or remove small service.  
    Regards
    Suman

  • Calling a object of class from other class's function with in a package

    Hello Sir,
    I have a package.package have two classes.I want to use object of one class in function of another class of this same package.
    Like that:
    one.java
    package co;
    public class one
    private String aa="Vijay";  //something like
    }main.java:
    package co;
    import java.util.Stack;
    public class main extends Stack
    public void show(one obj)
    push(obj);
    public static void main(String args[])
    main oo=new main();
    }when I compile main class, Its not compile.
    Its give error.can not resolve symbol:
    symbol: class one
    location: class co.main
    public void show(one obj)
                              ^Please help How that compile "Calling a object of class from other class's function with in a package" beacuse I want to use this funda in an application

    kumar.vijaydahiya wrote:
    .It is set in environment variable.path=C:\bea\jdk141_02\bin;.,C:\oraclexe\app\oracle\product\10.2.0\server\bin;. command is:
    c:\Core\co\javac one.javaIts compiled already.
    c:\Core\co\javac main.javaBut it give error.
    Both java classes in co package.Okay, open a command prompt and execute these two commands:
    // to compile both classes:
    javac -cp c:\Core c:\Core\co\*.java
    // to run your main-class:
    java -cp c:\Core co.main

  • Diffrence between Class.forName() and new Operator

    What is diffrence between class.forName() and new operator.Please tell in much detail.
    Also about classloader.loadclass.
    Suppose the class that we are tring to load with the help of class.forname is not compiled. Again if I make changes at runtime to that class will that get reflected.

    What is diffrence between class.forName() and new
    operator.Please tell in much detail.Class.forName loads a class. The new operator creates a new instance. Apple trees and apples.
    Also about classloader.loadclass.Read the API.
    Suppose the class that we are tring to load with the
    help of class.forname is not compiled.Then you can't load it and get an exception. Read the API.
    Again if I
    make changes at runtime to that class will that get
    reflected.Depends on the changes and when exactly you do them.

  • How pass table of objects between packages?

    I am trying to pass a table of objects between two packages in the same schema in Oracle 8i.
    In the schema, I defined the object:
    create type formObject as OBJECT (
    name VARCHAR2(50),
    type VARCHAR2(25));
    In package1 spec, I defined this (global to package):
    TYPE formTable IS TABLE OF formObject INDEX BY BINARY_INTEGER;
    In package1.procedure1 body:
    formWidgets formTable;
    added objects...
    the call..
    the_script := package2.generateScript(formWidgets, 2);
    In package2 spec, I defined this:
    TYPE formTable IS TABLE OF formObject INDEX BY BINARY_INTEGER;
    FUNCTION generateScript (formWidgets IN formTable, numberWidgets in BINARY_INTEGER) return varchar2;
    In package2.body:
    FUNCTION generateScript(formWidgets IN formTable, numberWidgets IN BINARY_INTEGER) return varchar2
    IS
    etc.
    I get the following compilation error in package 1 on the call to package 2:
    PLS-00306 - Wrong number or type of arguments in call to generateScript.
    Of course it works when the generateScript() module is in the same package as the calling module.
    Both tables are index-by binary_integer tables of type formObject, which is global to the schema, so why can't it figure out they are of the same type?
    I tried to then make the table itself global to the schema by this:
    create or replace TYPE formTable as TABLE OF formObject INDEX BY BINARY_INTEGER;
    but I get a compilation error.
    What do I need to do to get this to work?
    I would eventually like to be able to pass the table of objects between schemas. Can this be done in 8i?
    Any help would be greatly appreciated.

    Both packages have to use the same table definition, not only the same kind of definition.
    Put your table definition in the spec. of package 1, e.g.
    package p_one is
    type my_tab is table of x index by binary integer;
    In package 2, you create your function definition like
    package p_two is
    function do_it (p_tab in p_one.my_tab)
    and so on, this should work.

  • Using Smart objects between documents

    I know how to make smart objects within a single document, but Is it possible to use Smart objects between separate psd files?
    I would like to create a master background file and have any changes made to this updated throughout all the other psd documents that contain this.
    I cant find any info on this...Can it be done?
    thanks
    Jeff

    No a smart object layer contains a copy of the original in the layer.  If you then change the orignal the copy in the smart object layer is not updated and if you change the copy in the smart object layer the original is not changed. Smart Object are independant from the original.  It is posible to have multipal smart object layers that contain the same smart object in a single document. You can change the single smart object from any of the layers that its in.  You can also have independant smart object layers of the same image. That the difference between dupeing a smart object layer and using menu layers>smart objects>new smart object via copy. 

Maybe you are looking for