EJB 3.1 @Asynchronous and calling other methods from within

Hey all,
I am helping a friend set up a test framework, and I've turned him on to using JEE6 for the task. I am decently familiar with entity beans, session beans, and such. One of the new features is @Asynchronous, allowing a method to be ran on a separate thread. The test framework generally needs to spawn potentially 1000's of threads to simulate multiple users at once. Originally I was doing this using the Executor classes, but I've since learned that for some reason, spawning your own threads within a JEE container is "not allowed" or bad to do. I honestly don't quite know why this is.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
Thanks.

851827 wrote:
Hey all,.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
Yes since the EE spec delegated thread management to conatiners, the container might assume that some info is available in the thread context that you may not have made available to your threads.
Also threading is a technical implementation detail and the drive with the EE spec is that you should concentrate on business requirements and let the container do the plumbing part.
If you were managing your own threads spawned from EJBs, you'd have to be managing your EJBs' lifecycle as well. This would just add to more plumbing code by the developer and typically requires writting platform specific routines which the containers already do anyway.
>
None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
Thanks.If you want to be asynchronous without caring about a return value then just use MDBs.
The async methods have no restrictions on container services and there is nothing wrong with calling other non async methods. Once the async method is reached those annotations don't matter anyway (unless if you call thhose methods from a new reference of the EJB that you look up) as they only make sense in a client context.
Why do you need to make the call to the servlet from the EJB? Makes it difficult to know who is the client here. Better use the Future objects and let the initial caller delegate to the other client components as needed.

Similar Messages

  • Calling parent method from within child object

    Hello,
    A quick question! Is it possible to call a method in a parent object from within a child object.By child object I mean an object that was instantiated within the parent object.
    Thanks.

    A quick question! Is it possible to call a method in a
    parent object from within a child object.By child
    object I mean an object that was instantiated within
    the parent object.Since you are using ambiguous terminology, it would be much better if you provided a small sample of your code to avoid confusion. I am guessing that you are actually talking about an inner class when you say child class.
    If that is correct, then you can do something like this:
    class Parent {
      void foo() {}
      void bar() {}
      class Child {
        void foo() {}
        void test() {
          bar(); // No conflicts, just call the Parent method
          Parent.this.foo(); // Use explicit qualification to avoid conflicts.

  • How to expose and call AM methods from plain java (testability etc)?

    Hello,
    my project is just starting out with the OA Framework. We just encountered our first hurdle - I hope someone here can help out or at least point me in the right direction. None of this stuff seems to be explicitly mentioned in the standard OAF documentation.
    This is the situation: We need to call the logic in our Application Modules directly. Two reasons for this:
    - We need to expose methods in the AM as web services
    - We really want to create unit\integration tests (probably JUnit) and set up some sort of continous integration environment (Cruisecontrol or similar).
    Now, how do we go about this? I see that controller code usually does something a la this:
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    This doesn't seem viable for plain javacode, since there is no pageContext or web beans in that situation.
    Now, I allready tried the most naive approach (tried it in the OAF Tutorial):
    EmployeeAMImpl employeeAMImpl = new EmployeeAMImpl();
    This of course doesn't work, since none of the VO\EO seem to be instantiated, db connection is probably not set up etc.
    The third approach is the one I found in the javadoc for OAApplicationModuleImpl:
    // load some basic properties
    Properties properties = loadProperties();
    javax.naming.Context ic = new InitialContext(properties);
    // 'defName' is the JNDI name for the application module
    // definition from which the root Application Module is to be created
    String defName = "abc.xyz.SampleApplicationModule";
    oracle.jbo.ApplicationModuleHome home = ic.lookup(defName);
    return home.create();
    This seems more promising this far, however I need help with the following two questions:
    1: Do I really need to go through JNDI to access my AMs from plain javacode (JUnit tests, webservices etc)? If not, how do I then instantiate AMs, complete with EOs, VOs etc?
    2: If I do need to go through JNDI: what is the easiest way to register and subsequently call my AMs and their logic\context, particularly for usage from web services and testing frameworks (JUnit etc)?
    I'm kinda stumped here, guys. How have you solved this, if you haven't then how would you go about doing it?

    Hello,
    my project is just starting out with the OA Framework. We just encountered our first hurdle - I hope someone here can help out or at least point me in the right direction. None of this stuff seems to be explicitly mentioned in the standard OAF documentation.
    This is the situation: We need to call the logic in our Application Modules directly. Two reasons for this:
    - We need to expose methods in the AM as web services
    - We really want to create unit\integration tests (probably JUnit) and set up some sort of continous integration environment (Cruisecontrol or similar).
    Now, how do we go about this? I see that controller code usually does something a la this:
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    This doesn't seem viable for plain javacode, since there is no pageContext or web beans in that situation.
    Now, I allready tried the most naive approach (tried it in the OAF Tutorial):
    EmployeeAMImpl employeeAMImpl = new EmployeeAMImpl();
    This of course doesn't work, since none of the VO\EO seem to be instantiated, db connection is probably not set up etc.
    The third approach is the one I found in the javadoc for OAApplicationModuleImpl:
    // load some basic properties
    Properties properties = loadProperties();
    javax.naming.Context ic = new InitialContext(properties);
    // 'defName' is the JNDI name for the application module
    // definition from which the root Application Module is to be created
    String defName = "abc.xyz.SampleApplicationModule";
    oracle.jbo.ApplicationModuleHome home = ic.lookup(defName);
    return home.create();
    This seems more promising this far, however I need help with the following two questions:
    1: Do I really need to go through JNDI to access my AMs from plain javacode (JUnit tests, webservices etc)? If not, how do I then instantiate AMs, complete with EOs, VOs etc?
    2: If I do need to go through JNDI: what is the easiest way to register and subsequently call my AMs and their logic\context, particularly for usage from web services and testing frameworks (JUnit etc)?
    I'm kinda stumped here, guys. How have you solved this, if you haven't then how would you go about doing it?

  • No access to method from within the same class

    Hey there.
    First I have to excuse my English for I'm german and just learning...
    Ok, my problem is as follows. I have a class called JDBC_Wrapper it includes the method sendQuery(String query). When I call this method from within another class (where 'wrapper' is my instance of JDBC_Wrapper) it works fine. For example:
    wrapper.sendQuery("SELECT * FROM myDataBase");
    But then I have written a method called getNumRows() into my JDBC_Wrapper class.
    This method should send a query through sendQuery(Strin query) but when calling getNumRows() it says: "java.sql.SQLException: [FileMaker][ODBC FileMaker Pro driver][FileMaker Pro]Unbekannter Fehler." (Unbekannter Fehler -> Unknown Exception). What could that be?
    I'm using jdk2 sdk 1.4.2 with BlueJ. My database is Filemaker Pro 6. The ODBC/JDBC connector works fine.
    BerndZack

    This is within my JDBC_Wrapper class:
    public ResultSet sendQuery(String query)
            if(connected)
                try
                    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet rs = s.executeQuery(query);
                    return rs;
                catch(Exception e)
                    System.out.println(e);
            else
                //System.out.println("There is no connection to the datasource!");
            return null;
    public int getNumRows()
            try
                ResultSet r;
                r = this.sendQuery("SELECT COUNT(*) FROM " + table_name); // At this line the error occurs
                r.next();
                return (int)r.getInt(1);
            catch(Exception e)
                System.out.println(e.getMessage());
                return -1;
    }When I call sendQuery() from within another class it works, but calling getNumRows()
    throws an exception.

  • In session and call tansaction methods, which is better . why?

    hi
    in session and call tansaction methods, which is better . why?

    see the link:
    <a href="http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/">batch inpunt VS call transaction</a>
    "The most important aspects of the session interface are:
    <b>Asynchronous processing</b>
    Transfer data for multiple transactions
    Synchronous database update. During processing, no transaction is started until the previous transaction has been written to the database.
    A batch input processing log is generated for each session
    Sessions cannot be generated in parallel. The batch input program must not open a session until it has closed the preceding session.
    The most important features of CALL TRANSACTION USING are:
    <b>Synchronous processing</b>
    Transfer of data from an individual transaction each time the statement CALL TRANSACTION USING is called
    You can update the database both synchronously and asynchronously. The program specifies the update type.
    Separate LUW (Logical Units of Work) for the transaction. The system executes a database commit immediately before and after the CALL TRANSACTION USING statement.
    No batch input processing log"
    I hope I have been able to help you.
    cordial greetings.

  • Difference between Session method and Call transaction method

    Hi,
    Difference between Session method and Call transaction method in BDC

    Hi,
    SESSION method:
    Is a standard procedure for transferring large amount of data into the R/3 system.
    Data consistency is ensured because batch input uses all thje checks conducted on the normal screen.
    It is a two step procedure:
    1.  Progarm: creates batch input session. This session is the data file that includes everything to begin the transaction.
    2. Process session: Which then actually transfers the data to database table.
    In this method an ABAP/4 program reads the external data that is to be entered in the SAP system and stores the data in a session.
    A session stores the actions that are required to enter your data using normal SAP transactions i.e. data is transferred to session which inturn transfers data to database table. Session is an intermediate step between internal table and database table.
    Data along with it's actions are stored in session. i.e. data for screen fields, to which screen it is passed, the program name behind it and how next screen is processed.
    When the program has finished generating the session, u can run the session to execute the SAP transactions in it.
    BDC_OPEN_GROUP
              You create the session through program by BDC_OPEN_GROUP function.
    1) User Name: User Name.
    2) Group       : Name of the session
    3) Lock Date : The date when you want to process the session.
    4) Keep        : This parameter is passed as 'X' when you want to retain session even       after processing it.                    
    BDC_INSERT
         Data is transferred to session by BDC_INSERT.
    BDC_CLOSE_GROUP.
         With this function the session will be closed.
    CALL TRANSACTION method.
    Syntax: call transaction <tr code> using <bdctab>
                                 mode <A/N/E>
                                 update <S/A>
                                 messages into <internal table>.
    <tr code>   : transaction code
    <bdctab>   : Name of the BDC table
    mode: mode in which you execute the transaction.      
    A   : all screen mode ( all the screens of the transaction are displayed )
    N   : no screen mode ( no screen will be displayed when you execute the transaction )
    E   : error screen ( only those screens are displayed where in you have error record )
    Update type:
    S: synchronous update in which if you change data of one table then all the related tables gets updated and SY_SUBRC is returned for once and all.
    A: asynchronous update in which if you change data of one table, the sy-subrc is returned and then updation of other affected tables takes place. So if system fails to update other tables still sy-subrc returned is zero.(that is when first table gets updated ).
    messages: if you update database table, operation is either successful or unsuccessful. These messages are stored in internal table. This internal table structure is like BDCMSGCOLL.
           TCODE:  transaction code.
           DYNAME: batch input module name.
           DYNNUMB: batch input dyn no.
           MSGTYP:  batch input message type.
           MSGSPRA: batch input language id of message.
           MSGID:    message id.
           MSGV1….MSGV5: message variables
    For each entry which is updated in the database table message is available in BDCMSGCOLL.
    Reward if useful
    Regards
    Srinu

  • Error while updating data using session and call transaction method

    Hi all,
        i have to update data using MM01 transaction from flat file to database.i have used both session method and call transaction method to do that.in both the methods data has been transferred from internal tables to screens but while updating the data that is by clicking the ok-code at the end of the transaction iam getting a dialogue box stating
       SAP EXPRESS DOCUMENT "UPDATE WAS TERMINATED" RECEIVED FROM AUTHOR "SAP".
      please tell whether the problem lies and solution for that.
                                       thanks and regards.

    hi,
    check your recording.check whether u saved your material no in recording or not.
    once again record the transacton mm01.
           MATNR LIKE RMMG1-MATNR,
           MBRSH LIKE RMMG1-MBRSH,
           MTART LIKE RMMG1-MTART,
           MAKTX LIKE MAKT-MAKTX,
           MEINS LIKE MARA-MEINS,
           MATKL LIKE MARA-MATKL,
           BISMT LIKE MARA-BISMT,
           EXTWG LIKE MARA-EXTWG,
    these are the fields which u have to take in internal table.
    this is the record which i took in my flatfile.use filetype as asc and hasfieldseperator as 'X'.
    SUDHU-6     R     ROH     MATSUDHU     "     001     7890     AA
    i did the same.but i didn't get any error.

  • Log file in session and call transaction methods

    Hi Experts,
    How to see log file in session and call transaction methods?

    hi
    If its a session then goto SM35, select ur session and then u can see log button over there at the top... that will give the log
    If its a call transaction then in ur program u need to declare internal table IT_MSGS like this
    DATA:  IT_MSGS LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
      LOOP AT IT_SALES.
        PERFORM POPULATE_BDC.
        CALL TRANSACTION 'VA01' USING IT_BDCDATA
                                      MODE MODE
                                      UPDATE UPDATE
                                      MESSAGES INTO IT_MSGS.
        IF NOT IT_MSGS[] IS INITIAL.
          LOOP AT IT_MSGS.
            CALL FUNCTION 'FORMAT_MESSAGE'
              EXPORTING
                ID        = IT_MSGS-MSGID
                LANG      = 'EN'
                NO        = IT_MSGS-MSGNR
                V1        = IT_MSGS-MSGV1
                V2        = IT_MSGS-MSGV2
                V3        = IT_MSGS-MSGV3
                V4        = IT_MSGS-MSGV4
              IMPORTING
                MSG       = V_MSG
              EXCEPTIONS
                NOT_FOUND = 1
                OTHERS    = 2.
            IF SY-SUBRC <> 0.
              MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
            WRITE:/ V_MSG.
          ENDLOOP.
        ENDIF.
      ENDLOOP.
    This will create a log for you, dont forget to award points if found helpful

  • Call C# method from javascript in WebView and retrieve the return value

    The issue I am facing is the following :
    I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
    In an WPF Desktop application, it would not be an issue because a WebBrowser
    (the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
    In an Windows Store Application, it is slightly different because the WebView
    only contains an event ScriptNotify to which we can subscribe like in the example below :
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    this.webView.ScriptNotify += webView_ScriptNotify;
    When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
    function CallCSharp() {
    var returnValue;
    window.external.notify(parameter);
    return returnValue;
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = DoSomerthing(parameter);
    The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
    A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = ReturnResult();
    await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
    var result;
    function CallCSharp() {
    window.external.notify(parameter);
    return result;
    function CSharpCallResult(parameter){
    result = parameter;
    However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
    window.external.notify does not wait for the C# to finish to execute.
    Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.

    I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my  CallCSharp
    function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
    CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
    CallCSharp function more look like the code below.
    function CallCSharp() {
    if (isAndroid()) {
    //mechanism to call C# method from js in Android
    //return the result of call to C# method
    } else if (isWindowsStoreApp()) {
    window.external.notify(parameter);
    // should return the result of call to C# method
    } else {
    In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility.

  • Mappimg and updation in bdc 'session ' and 'call transaction' methods

    What will happen if error record comes while updating in session method and call transaction method.

    Hi,
    If any error comes in Session method U can find that error in SM35->Log
    and updste again database for those enteries
    In cll transaction Method U have to handel error manually . for this u have to use structure BDCMSGCOL and Table T100.
    Regards
    Gaurav

  • Converting a string to Class object and calling its method

    I have recently moved to Java and I need help on this specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have the method called checkModule in them. I need to instantiate each class and run the checkMethod which returns true or false. My problem is that I am trying to get the name of the module (if it is ValModule1 or 2 or 3) from the user. What I get from the user is the name of the class for which I should call checkModule method on.
    how can I convert this string validationname given by the user and instantiate that class and call the method?
    I have tried this:
    String str="c:/xpathtest/src/Plugin_Config.xml";
    File xmlDocument = new File(str);
    String cls = "ValModule1"; // assuming this is what the user gave me
    Class t = Class.forName("ValModule1");
    Object o = t.newInstance();
    After that if I try
    if(o.checkModule(xmlDocument)){
    $i++;
    It gives me an error saying that it is not an existing method
    cannot resolve symbol
    [javac] symbol : method checkModule (java.io.File)
    [javac] location: class java.lang.Object
    [javac] if(o.checkModule(xmlDocument)){
    [javac] ^
    [javac] 1 error
    Can you please let me know where I am screwing up :-) ? If you need me to put both the programs I can do that too. Thanks in Anticipation

    I have recently moved to Java and I need help on this
    specific issue given below.
    I have to do this :
    ValModule1 val1 = new ValModule1();
    ValModule2 val2 = new ValModule2();
    if(val1.checkModule(xmlDocument)){
    $i++;
    There are many ValModule* classes and they all have
    the method called checkModule in them. I need to
    instantiate each class and run the checkMethod which
    returns true or false. My problem is that I am trying
    to get the name of the module (if it is ValModule1 or
    2 or 3) from the user. What I get from the user is
    the name of the class for which I should call
    checkModule method on.
    how can I convert this string validationname given by
    the user and instantiate that class and call the
    method?
    Define an interface containing the method all your classes have in common, cast the Object reference returned by newInstance to that interface, then you can call that method.
    Good Luck
    Lee

  • Where can i find the theory for session and call transaction method

    hi
    where can i find the theory for session and call transaction method
    bye

    check this link
    http://www.sap-img.com/abap/learning-bdc-programming.htm
    http://www.planetsap.com/bdc_main_page.htm
    lsmw, bapi, bdc- session, bdc-calltransaction
    u can get it in help.sap.com also

  • Call Java Method from BPM Process

    Hi,
      I have defined a java class with set of methods , and I want to know if there is any way to call those methods from a BPM process..
    Thanks in Advance,,
    Best Regards,,
    Ola Essa..

    Use the spring component context in soa suite instead of ejb. Look for documentation in soa suite developer guide. Only if you have existing ejbs then use ejb adapters.
    See this http://www.oracle.com/technetwork/middleware/soasuite/learnmore/fivecoolusecasesforspring-1885529.pdf
    Vikram
    Message was edited by: VikramFusionApplied

  • How to call a set method from within a constructor

    Hello,
    I want to be able to call a set method from within a Scanner, to be used as the argument to pass to the Scanner (from a source file). Here's what i tried:
    private void openFiles()
            input = new Scanner( setSource );              
        and here is the set method:
    public String setSource( String in )
            source = in;
            return source;
        }obviously there will be more code in this method but i'm trying to tackle one problem at a time. Thanks in advance..

    The "String in" declaration says: "Nobody may ever invoke setSource() without specifying a certain String. The content of the String is known at run-time only."
    In no place in your code you say the compiler: "I want the 'in' variable (actually, parameter) of method setSource() to contain the first arg which is passed to the application".
    This is exactly the same mechanism allowing you to write "new Scanner" with something inside the two parentheses.

  • Operation not found error while calling AM methods from managed bean

    Hi,
    operation not found error while calling AM methods from managed bean.
    written a method with two parameters in AM.
    exposed the method in AM client interface
    in the page bindings added the method in method action ..left empty in the value fields of the parameters.
    calling the method from managed bean like below
    String userNameVal = (String)userName.getValue();
    String passwordVal = (String)password.getValue();
    OperationBinding operationBinding =
    ADFUtils.findOperation("verifyLogin");
    operationBinding.getParamsMap().put("userName",userNameVal);
    operationBinding.getParamsMap().put("password",passwordVal);
    operationBinding.execute();
    i am getting operation verifyLogin not found error.Please suggest me something to do.
    Thanks
    Satya

    Hi vlsn,
    Can you try with the below code
    // in your backing bean
    OperationBinding operation = bindings.getOperationBinding("verifyLogin");
    //Put your both parameters here
    operation.getParamsMap().put("parameter_name1", parameterValue1);
    operation.getParamsMap().put("parameter_name2", parameterValue2);
    operation.execute();
    if (operation.getResult() != null) {
    Boolean result = (Boolean) operation.getResult();
    and share the result.
    regards,
    Rajan

Maybe you are looking for