One method used in two classes

Hi
I have one method in class A and I need to use it (only this method) in class B. what should I do? Should I create subclass within class A with this method, and then use it in class B or create completely different class C with only this method?
Thanks
waso

It's a good idea to use Java conventions about cAsE: especially since boolean and Boolean are different beasts.
So:
public class MyExample {
    public boolean example() {
        System.out.println("My example");
        return true;
}You use it in some other class B like this:
class B {
    void someMethod() {
        MyExample eg = new MyExample();
        boolean result = eg.example();
        System.out.println("example() returned " + result + " (as expected!)");
}There's no subclassing ("in" A or elsewhere).
This is a bit of a contrived example, because example() always returns the same thing. eg is initialised as an instance of MyExample but that class has no state so the method is effectively static. If MyExample had state and the method call did something genuine involving this state, then things would get interesting - and it is precisely then that subclassing, extracting someMethod() into some other class, or inlining it where it was used would make no sense.
Edited by: pbrockway2 on Jul 12, 2008 9:26 PM

Similar Messages

  • Stateless session's one method to call  two bmp's create method

    JSP calls one stateless session's one method and the method calls two bmps'
              create method.
              However, When the second bmp run the create operation, the exception
              happens.
              But the date that the first bmp insert is not rollbacked.
              How can I rollback all data, when the exception happens?
              

    Use JSP actions.
    <jsp:useBean id="shoppingCart" class="com.package.Cart" scope="session">
    <jsp:setProperty name="shoppingCart" property="userName" value="Guest" />
    </jsp:useBean>

  • One performance view for two classes, possible?

    Hi there,
    My system is still running 2007 R2. I am writing a MP now which contains two classes. There are few performance collection rules targeting those two classes. I want to create one performance view to display performance data for BOTH classes. Is it possible?
    I already created an instance group and added both classes as member of the group. By using the group, I can created one alert view to display alerts from either class. Can I use the same trick for the performance view? Thanks!

    In addition, we also can add a dashboard view with two columns for the two classes, and add performance widget for each column.
    Regards,
    Yan Li
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • How to define namespace with one XSD using in two different DB-Locations ?

    I'm not clear,How to define namespace, targetnamespace, schemaLocation or NoNamespaceSchemaLocation
    when using one common schema.xsd-definition
    in two different database-locations for exchange xml-documents?
    when insert xml-document I've got an error ORA-30937
    do you have an good exsample ?
    thanks
    Norbert
    schema :
    <xs:schema
    xmlns="http://sourcehost.com/namespace"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:oraxdb="http://xmlns.oracle.com/xdb"
    targetNamespace="http://sourcehost.com/namespace"
    xml-document :
    xmlns="http://Sourcehost.com/namespace"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:SchemaLocation="http://sourcehost.com/namespace http://desthost:8080/sys/schemas/PUBLIC/ADRESSEN.XSD">
    SQL> insert into ADRESSEN values
    (XMLType
    (bfilename ( 'XMLIMPORT_DIR', 'adressen.xml')
    , 0 )
    --> error :
    ORA-30937: No Schemadefinition for "SchemaLocation" (Namespace "http://www.w3.org/2001/XMLSchema-instance") in übergeordnetem Knoten "/ADRESSEN"

    Norbert
    The schema location used to register the XML schema with XML DB does not need to be a valid URL for accessing the XML Schema
    I can use the same URL , for instance
    http://xmlns.example.scom/xsd/myXMLSchema.xsd
    on machines dbserver1, and dbserver2. The only reason some people choose to use the hostname / portnumber convention is that this makes it possible to validate the XML Instance documents against the copy of the XML schema stored in the XML DB repository using an external tool like XMLSpy without have to add entries to XMLSpy's OASIS catalog files.
    I am concerned about the message you are getting. That's not correct AFAICT but I'd need to see the complete XML Schema and Instance to be sure.

  • One control used in two ways??

    Hi,
    Is there a possibility to use a Combo control as a text control or vice-versa?
    I need to use one control with two functionalities, one to enter a free text and other to select from combo list at the same time. (In search scenario)
    Thanks & Regards,
    Praveen.

    Hi,
    no, this is not possible as normally there is a combo validation active for the underlying BQ property.
    What you can do is to create 2 controls, one for the combo, one for free text and put them exactly on top of each other., both of them hidden.
    In the onload event and in the place where you are able to decide which should be active you can toggle the property from hidden to normal and vice versa for both controls.
    Of course both controls need to be unbound and mapped to the particular BQ property/properties but this depends from your scenario.
    Regards,
    Wolfhard

  • One VO used on two pages creating problem.-Nullpointer error

    Hello All,
    I have extended one VO on one page "ponAwardByQuotePG". I am done with that. But this VO is used on second next page as well.
    After pressing one "AWARD" button on 1st page , it goes to 2nd page "ponAwardQuotePG". Both these pages use same VO which i have extended. Whenever I press Save Award GO button on second page, it throws NULLPOINTER exception error attached herewith. I have also attached the flow of steps along with corresponding VO and AM code.
    I found following thing in 2nd page's CO even though my VO is extended as "XXEGAAwardByQuoteVOEx" , its showing following in CO:
    AwardByQuoteVO awardbyquotevo = (AwardByQuoteVO)awardbyquoteam.findViewObject("AwardByQuoteVO");
    Please guide what could be the reason (Contact me at [email protected] so that i can send you some more document as attachment.)
    Following is the error stack:
    "java.lang.NullPointerException<br /><br /> at oracle.apps.pon.award.creation.webui.AwardQuoteCO.processFormRequest(AwardQuoteCO.java:1710)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:810)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)<br /><br /> at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1159)<br /><br /> at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:1022)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:988)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:843)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)<br /><br /> at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:1022)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:988)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:843)<br /><br /> at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)<br /><br /> at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363)<br /><br /> at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2676)<br /><br /> at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1683)<br /><br /> at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:509)<br /><br /> at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:430)<br /><br /> at _oa__html._OA._jspService(_OA.java:84)<br /><br /> at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)<br /><br /> at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:417)<br /><br /> at oracle.jsp.JspServlet.doDispatch(JspServlet.java:267)<br /><br /> at oracle.jsp.JspServlet.internalService(JspServlet.java:186)<br /><br /> at oracle.jsp.JspServlet.service(JspServlet.java:156)<br /><br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)<br /><br /> at org.apache.jserv.JServConnection.processRequest(JServConnection.java:456)<br /><br /> at org.apache.jserv.JServConnection.run(JServConnection.java:294)<br /><br /> at java.lang.Thread.run(Thread.java:619)"

    I found following thing in 2nd page's CO even though my VO is extended as "XXEGAAwardByQuoteVOEx" , its showing following in CO:
    AwardByQuoteVO awardbyquotevo = (AwardByQuoteVO)awardbyquoteam.findViewObject("AwardByQuoteVO");controller code won't change when you substitute the VO. You will see it only at the runtime.
    And to verify the substitution at the run time, select the "About this Page" link and expand the "Business Component References Details".
    And to debug the error in the standard controller, you need to decompile the controller file and include it in your project.
    This will show you the exact problem from where you can proceed further. You can use jad tool for decompilation.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Is it possible to have one library used between two users?

    Hello, I am setting up a friend's computer to have a seperate user for him and for his wife. The computer has been in use for about a year with just one user. Adding the second one makes sense for everything they use the computer for--except iPhoto. They have roughly 11,000 images in the library and want to be able to access, edit, export, etc them from whichever user is logged on. They would like it to work so that when one user adds images to the library, the other user has access to them as well. I looked into the sharing photos option, but it seems to restrict you to read only access when viewing shared libraries. Any suggestions on the best option for them? They are using a dual G5 Tower running iPhoto 5.0.4
    Thanks, Alan
    Powerbook 1.25 GHZ    

    Hey,
    saw this in macworld:
    (I haven't tried this, but it does indicate that permissions include read and write)
    Family Album
    My son and I share an iMac at home. Is there a way for us to use the same iPhoto library?—Kiki Mulliner
    With the proper privileges, this can be done with aliases. It works this way:
    Choose the most up-to-date iPhoto Library folder (located at your user folder/Pictures) and move it to the Shared folder inside the Users folder at the root level of the hard drive. Click on the iPhoto Library folder, press Command-I to call up the iPhoto Library Info window, click on the Ownership & Permissions triangle, and then click on the Details triangle below. Select Read & Write from the Access pop-up menu directly beneath the Group pop-up menu, select Read & Write from the Others pop-up menu, and then close the Info window. Hold down the Command and option keys and drag the iPhoto Library folder back to the Pictures folder to create an alias.
    Switch to your son’s user account, change the name of his iPhoto Library to something like iPhoto Library Old (in case you want to use this library again), open the Shared folder within the Users folder, and Command-option-drag that folder’s iPhoto Library folder to your son’s Pictures folder to create an alias.

  • Methods used in cl_gui_custom_container for ALV and for what purpose

    Methods used in cl_gui_custom_container for ALV and for what purpose and i want the exact senario for the usage of those method?
    2. What events are used in ALV?
    I anyone help me please,
    Points will be awarded.
    Thank you & Regards,
    Jagrut BharatKumar Shukla

    hey,
    look at this sample code....
    TABLES: SFLIGHT.
    G L O B A L   I N T E R N  A L   T A B L E S
    DATA: GI_SFLIGHT TYPE STANDARD TABLE OF SFLIGHT.
    G L O B A L   D A T A
    DATA: OKCODE LIKE SY-UCOMM,
          G_WA_SFLIGHT LIKE SFLIGHT.
    Declare reference variables to the ALV grid and the container
    DATA:
      GO_GRID             TYPE REF TO CL_GUI_ALV_GRID,
      GO_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    S T A R T - O F - S E L E C T I O N.
    START-OF-SELECTION.
      SET SCREEN '0100'.
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE USER_COMMAND_0100 INPUT.
      CASE OKCODE.
        WHEN 'EXIT'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  STATUS_0100  OUTPUT
    MODULE STATUS_0100 OUTPUT.
    Create objects
      IF GO_CUSTOM_CONTAINER IS INITIAL.
        CREATE OBJECT GO_CUSTOM_CONTAINER
          EXPORTING CONTAINER_NAME = 'ALV_CONTAINER'.
        CREATE OBJECT GO_GRID
          EXPORTING
            I_PARENT = GO_CUSTOM_CONTAINER.
        PERFORM LOAD_DATA_INTO_GRID.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Form  load_data_into_grid
    FORM LOAD_DATA_INTO_GRID.
    Read data from table SFLIGHT
      SELECT *
        FROM SFLIGHT
        INTO TABLE GI_SFLIGHT.
    Load data into the grid and display them
      CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          I_STRUCTURE_NAME = 'SFLIGHT'
        CHANGING
          IT_OUTTAB        = GI_SFLIGHT.
    ENDFORM.                    " load_data_into_grid
    <b>* the Events are</b>
    ITEM_DATA_EXPAND, REPREP_SEL_MODIFY, CALLER_EXIT, USER_COMMAND, TOP_OF_PAGE, DATA_CHANGED, TOP_OF_COVERPAGE, END_OF_COVERPAGE, FOREIGN_TOP_OF_PAGE, FOREIGN_END_OF_PAGE, PF_STATUS_SET, LIST_MODIFY, TOP_OF_LIST, END_OF_PAGE, END_OF_LIST,AFTER_LINE_OUTPUT, BEFORE_LINE_OUTPUT, SUBTOTAL_TEXT, CONTEXT_MENU.
    <b>the methods used with the class CL_GUI_CUSTOM_CONTAINER are as follows......</b>
    IF_CACHED_PROPGET_NEXT_PROP, IF_CACHED_PROPSEEK_FIRST_PROP, IF_CACHED_PROP~SET_PROP, IS_VALID, FREE, GET_PROPERTY, SET_PROPERTY, CALL_METHOD, ASSIGN_PROPERTY, CALL_METHOD_RESULT_GUI_OBJECT, GET_PROPERTY_GUI_OBJECT, IS_CACHED_PROP, ADD_CACHE_PROP, REMOVE_CACHE_PROP, GET_CACHE_PROP, SET_CACHE_PROP, IS_CACHE_VALID, INVALIDATE_CACHE, GET_FOCUS, SET_FOCUS, SET_NAME, GET_NAME, GET_ENABLE, SET_ENABLE, DISPATCH, FINALIZE, GET_ADJUST_DESIGN, GET_GRID_HANDLE, GET_GRID_STEP, GET_HEIGHT, GET_LEFT, GET_METRIC, GET_MODE, GET_REGISTERED_EVENTS, GET_TOP, GET_VISIBLE, GET_WIDTH, IS_ALIVE, REG_EVENT_LEFT_CLICK_DESIGN, REG_EVENT_LEFT_CLICK_RUN_MODE, REG_EVENT_MOVE_CONTROL, REG_EVENT_RIGHT_CLICK, REG_EVENT_SIZE_CONTROL, SET_ADJUST_DESIGN, SET_ALIGNMENT, SET_GRID_HANDLE, SET_GRID_STEP, SET_HEIGHT, SET_LEFT, SET_METRIC, SET_MODE, SET_POSITION, SET_REGISTERED_EVENTS, SET_TOP, SET_VISIBLE, SET_WIDTH, GET_PATH, CONTROL_REGISTER_EVENT, CONTROL_UNREGISTER_EVENT, GET_EVENT_PARAMETER, GET_REGISTERED_EVENTS_EX, GET_WINDOW_PROPERTY, INIT_CONTROL, INIT_CONTROL_WITH_HWND, REGISTER_CACHED_PROPERTY, REGISTER_CACHED_W_PROPERTY, SET_REGISTERED_EVENTS_EX, SET_WINDOW_PROPERTY, UNREGISTER_CACHED_PROPERTY, UNREGISTER_CACHED_W_PROPERTY, GET_CONTAINER_TYPE, RESIZE, GET_INNER_WIDTH, LINK, GET_LINK_INFO, GET_INNER_HEIGHT, SET_MODE_FOR_ALL, GET_DYNPRO_CONTAINER, GET_FRAME_CONTAINER, GET_CHILD, ADD_CHILD, REMOVE_CHILD, REMOVE_ALL_CHILDREN, CONSTRUCTOR.

  • How to use one commandButton  to execute two task in JSF

    I have a form in JSF page which contains different faces components. These faces bind to ADF BC to insert one row in the database when the user press commandButton. Also I need to bind the value of one inputText in that form to managed bean to execute another task in the application when the user press the same commandButton.
    The code of the inputText:
    <h:inputText value="#{bindings.ProjectNumber.inputValue}"
    id="pn"
    size="10"
    required="#{bindings.ProjectNumber.mandatory}">
    The code of commandButton:
    <h:commandButton actionListener="#{bindings.Commit.execute}"
    value="Save"
    disabled="#{bindings.Commit.actionEnabled}"/>
    The managed bean is “findInspector”. I tried to insert inputHidden inside commandButton tag and assign the value of the inputText to the inputHidden as follows:
    <h:commandButton actionListener="#{bindings.Commit.execute}"
    value="Save"
    disabled="#{bindings.Commit.actionEnabled}">
    <h:inputHidden value="#{bindings.ProjectNumber.inputValue}" binding="#{findInspector.project}"/>
    </h:commandButton>
    But it was not work
    Please how can I write the code to use the value of the inputText more than one time in the JSF(one to insert one row by using ADF BC and another to use the same value to bind to a managed bean) and how to use one commandButton to execute two task in JSF.
    Thank you
    Waheed

    Yes I did
    <managed-bean>
    <description>The bean for get project No</description>
    <managed-bean-name>projectBean</managed-bean-name>
    <managed-bean-class>
    mcscm.model.ProjectBean
    </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>bindings</property-name>
    <value>#{bindings}</value>
    </managed-property>
    </managed-bean>
    Also I changed the method in the managed bean as follows:
    public String commandButton_action() {
    FacesContext fctx = FacesContext.getCurrentInstance();
    ValueBinding vb = fctx.getApplication().createValueBinding("#{bindings}");
    DCBindingContainer dcb = (DCBindingContainer) vb.getValue(fctx);
    OperationBinding operation = (OperationBinding) dcb.get("projectNumber");
    operation.execute();
    return null;
    where projectNumber is my method in the java class of the application module "TaskInformationImpl". I made this method to be accessed from outside of ADF BC.
    I just create a sample code for projectNumber method for testing only as:
    public void projectNumber (String data){
    System.out.print(data);
    In the page Pagedef file I added this :
    <methodAction id="projectNumber"
    InstanceName="TaskInformationDataControl.dataProvider"
    DataControl="TaskInformationDataControl"
    MethodName="projectNumber" RequiresUpdateModel="true"
    Action="999" IsViewObjectMethod="false">
    <NamedData NDName="data" NDValue = "#{bindings.ProjectNumber.inputValue}" NDType="java.lang.String"/>
    After I did all of this I get a new error like:
    javax.faces.FacesException: #{projectBean.commandButton_action}: javax.faces.el.EvaluationException: java.lang.ClassCastException: oracle.adfinternal.view.faces.model.binding.FacesCtrlAttrsBinding cannot be cast to oracle.adf.model.OperationBinding
    Is it very difficult to do this in JDeveloper?. yes ADF BC provide me a lot of facilities, but when I want to do a specific task I face a lot of troubles

  • Using only one method in session bean to create web service

    Hi all,
    I hhave a scenario where i am inserting and retrieving data from dict table using web service.
    For this i have created a session bean and a wrapper class.
    The session bean has two methods: insertRecords(), and viewRec().
    so while creating a web service i need to include two methods.
    I want to have only one method where i can pass a parameter as operation and if it is "I", then i can call the insert method and if it is "S" i can call view method.
    I tried doing that bt i am stuck up with the return type.
    Insert method has return type as array of wrapper class and
    view method has wrapper class as return type ...
    Is this scenario possible..??
    or is there any other way to do this???
    Plz let me knw..
    Thankls n regards,
    Ankita

    Hi Siddharth,
    Im really sorry..
    i cudnt  get u ..
    Actually these r methods:
    public DemoDicModel[] viewRecords()
    and
    public DemoDicModel insertRecords(
              String title,
              String desc,
              String status)
    and im trying this:
    public DemoDicModel[] getMethods(String operation,String title,String desc, String st)
    DemoDicModel[] demoModel =null;
    DemoDicModel model = new DemoDicModel();
    if(operation == "show")
          demoModel = viewRecords();
    if(operation == "ins")
          model = insertRecords(title,desc,st);
          model.setMsg("RECORDS GENERATED");
          demoModel=
    return demoModel;
    im stuck up with insert operation.
    can  u plz explain me in detail.
    thanks,
    ankita

  • How shall I use an other class's methods in a class

    Hi all,
    I have two classes in the same directory. When I try to use a method of class in the other one, I get a compile error. Everything seems ok, bu could not understand the reason. The two classes and the error text are copied below. Any help will be appriciated.
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    public class MainThread extends Thread{
    //creating an object from CountryEnterence class
         private CountryEnterence cnt;
    public void MainThread(){
    start();
    public void run() {
    //calling a function of CountryEnternce class
    cnt.countryEnter(countryName,countryCode);
    /***And part of the CountryEnterence class is as belows:*/
    public class CountryEnterence{
    public countryEnter(String countryName,String countryCode){
    The error message when I try to compile MainThread is as follows:
    MainThread.java:17: cannot resolve symbol
    symbol :class CountryEnterence
    location :class MainThread
    private CountryEnterence conEnt;
    Regards,
    Dirgen

    hi Chuck, thanks for your reply.
    Infact the actual code defines the countryEnter() method with an integer return type.
    Here my real problem is as belows:
    C:/myDirectory/Class01.java
    C:/myDirectory/Class02.java
    public class Class01{
    private Class02 obj=new Class02();
    public void aMethod(){
    obj.aMethodOfClass02();
    When I try to compile Class01, I always get the error like "java can not resolve the symbol Class02"
    Do you think I am mistaking?

  • Method used to Find the Larger of two numbers

    I'm defining a method to compare two numbers, then print the result on a single line. This is what I have so far:
    public static void printLarger(int One, int Two)
    System.out.println(_____(One, Two));
    What method would I call to find which is larger? Is there a place where I can find common methods like this? Am I on the right track?
    Thanks in advance.

    try this
    public class PrintLarger
         static int a = 1;
         static int b = 2;
         public static void main(String args[])
              if(a>b)
                   System.out.println(a);
              else
                   System.out.println(b);
    That was like 15 minutes later. There's no way (okay, there is, but...) that you would recommend the iffing and the elsing over Math.max/min/whatever. Or over just using the ternary operator...
    The API is a wonderful thing. It prevents the same lines of code being written ad infinitum.
    Live it. Learn it. Love it.
    ~Cheers
    [rantwithsarcasm]

  • How to use java.lang.Class.getMethod() and java.lang.reflect.Method.invoke(

    I want to call a specified method of one class dynamically. I use the method
    "getMethod()" in package "java.lang.Class" to get method and "invoke()" in
    " java.lang.reflect.Method " to invoke method.
    The problem is as following :
    1. There are two argument in this method "getMethod(String MethodName , Class[] paremterTypes)" in package "Class". I have no idea about the second parameter " Class[] parameterTypes ".what does the argument exactly mean ?
    2. There are two argument in the method "invoke(object obj, object[] obj)" in package "Method".
    I have no idea about the second parameter "object[] obj ".what is mean ?
    I pass " null " value to it and it works.But i pass anothers ,jvm will throw exception.

    I have a generic Method Executer that has a method like
    public Object execute(String className, String methodName, Object args)
        String fullClassName = packageName + className ;
        Class delegateClass = Class.forName(fullClassName);
        BaseDelegate delegate = (BaseDelegate)delegateClass.newInstance();
        Method method = null;
        if (args == null)
            method = delegateClass.getMethod(methodName, new Class[] {});
            obj = method.invoke(delegate,new Object[] {});
        else
            method = delegateClass.getMethod(methodName, new Class[] {args.getClass()});
            obj = method.invoke(delegate, new Object[]{args});
       }This seems to have problems when I call the method from a class like:
    execute("CategoryDelegate", "getCategoryById", new Integer(4144));(I get a NoSuchMethodException)
    The method I am trying to execute in CategoryDelegate looks like:
    public Category getCategoryById(int categoryId) throws DelegateExceptionI think it has to deal with the difference in the way we handle Primitive Wrappers and Objects. Wrapper we have to use Interger.TYPE and with the rest of the Objects we have to use obj.class.
    Am I doing something wrong here? Any suggestions to make it work for primitive wrappers as well as Objects?

  • HT204053 Can I use one Apple ID for two Apple IPhones?

    Can I use one Apple ID for two Apple IPhones? I received an answer of yes.
    Now another question.  I have one ICloud Account, Two IPhones.  Can I use Find my IPhone via the one ICloud Account?  Can I see two IPhones on the map at the same time?  or do I need to view the second phone via some other method.
    Message was edited by: Hunter3D

    Yes.
    Cheers,
    GB

  • Synchronized method in a java class used by many interfaces

    My interface (idoc to file) is using a java class, which has one method that reads a table from a central database and after doing some calculations updates it.
    (The interface instantiate the class inside a user-defined function and calls the method there.)
    The problem is that if somebody sends 100 idocs at the same time, there can be a “dirty read”, I mean, a read just before other interface updates the table.
    We want the following:
    Interface 1:
    -          Read counter from the table (counter = 5 )
    -          Increment counter (counter = 6)
    -          Update table with that counter (table with counter = 6)
    Interface 2:
    -          Read counter from the table (counter = 6 )
    -          Increment counter (counter = 7)
    -          Update table with that counter (table with counter = 7)
    RESULT: The table has the counter = 7
    But what is happening is the following:
    -          Interface 1 reads (counter = 5)
    -          Interface 2 reads (counter = 5)
    -          Interface 1 increments counter (counter = 6)
    -          Interface 2 increments counter (counter = 6)
    -          Interface 1 updates table (table with counter = 6)
    -          Interface 2 updates table (table with counter = 6)
    RESULT: The table has the counter = 6 (WRONG)
    I made the method synchronized. What I was expecting was that only one interface (i1) could enter the method (read the table and update it) while other interfaces running at the same time would have to wait until i1 finished that method.
    My first test indicates that's not happening. Can anybody help me to find a solution?

    Hi Bhavesh,
    If the QOS is EOIO this means that the integration engine manage the call to the mapping program (and all the other blocks) inside an "internal" synchronized method.
    So this means that in this case you do not need to manage the queued access (synchronization) inside your custom java code because it is already enveloped in a queued block by XI.
    The problem that Jorge had can be easily reproduced using the sample code that follows:
    <b>class Synch Object</b>
    import java.util.Date;
    public class SynchObject {
         String strName;
         public SynchObject(String strName){
              this.strName = strName;
         public synchronized void syncWrite(String strCaller) throws InterruptedException{
              Date now;
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " entering syncWrite of " + strName);
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " syncWrite of " + strName + " called by " + strCaller );
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " leaving syncWrite of " + strName);
              System.out.println("");
              System.out.flush();
    <b>class Caller</b>
    public class Caller implements Runnable {
         String strName;
         SynchObject target;
         int intMax;
         public Caller(String strName, SynchObject target, int intMax) {
              this.strName = strName;
              this.target = target;
              this.intMax = intMax;
         public void run() {
              for(int i=0; i<intMax;i++)
                   try {
                        target.syncWrite(strName);
                   } catch (InterruptedException e) {
                        e.printStackTrace();
    <b>class Workbench</b>
    public class Workbench {
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              SynchObject sObj1 = new SynchObject("syncObj1");
              SynchObject sObj2 = new SynchObject("syncObj2");
              Caller c1 = new Caller("caller1",sObj1,2);
              Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
              Thread ct1 = new Thread(c1);
              Thread ct2 = new Thread(c2);
              ct1.start();
              ct2.start();
    Run the workbench class to see what happen when setting QOS EOIO (the synch object is the same).
    To see instead what happen now (missing synchronization) you have to change in Workbench class the statement
    Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
    with
    Caller c2 = new Caller("caller2",sObj2,2); '[*CHANGE*]
    The reason is that every instance of the mapping program declare a new instance of the "Synchronized object" so the calls are synchronized inside the same mapping program but not between several mapping program.
    Hope this give you a better idea on this problems with java synchronization, but if you have further doubts (I know it's a little bit tricky ) feel free to ask.
    Kind Regards,
    Sergio

Maybe you are looking for