Order of execution of Callable objects in an ExecutorService

what determines the order of execution of Callable objects in an ExecutorService ?
here is my test code:
    ExecutorService exe = Executors.newCachedThreadPool();
    Set<Callable<String>> tasks = new HashSet<Callable<String>>();
    for (int i = 0; i < 10; i++) {
      Worker worker = new Worker(i);
      tasks.add(worker);
    List<Future<String>> results = exe.invokeAll(tasks);
    for(int i = 0; i < results.size(); i++) {
      Future f = (Future) results.get(i);
      String s = (String) f.get();
      System.out.println("__" + s);
public class Worker implements Callable<String> {
  private int seqNumb = -111;
  public Worker(int i) {
    this.seqNumb = i;
  public String call() {
    double d = Math.random();
    int i = (int) (d * 10000);
    Thread.sleep(i);
    return (Integer.toString(i) + "___" + seqNumb);
}i ran this code within NetBeans on one XP machine. and ran it from the command line on a different XP machine.
the sequence is always:
*6*
*9*
*4*
*3*
*8*
*1*
*0*
*5*
*2*
*7*
the sequence should be random because of the random wait???
the sequence looks random. why does "6" come before "9"? why is "7" last?
yet, the sequence is always the same.
i can't understand the order of execution of the Callable objects.
note:
what i'm trying to do is implement my own version of the ExecutorService interface.
so, its important to understand the above question?
Edited by: kogose on Feb 9, 2009 6:53 PM

jtahlborn wrote:
ejp wrote:
2. The order of execution is defined by the queue associated with the ExecutorService. Normally it is a FIFO, but one can imagine using a PriorityQueue, given some kind of priority implementation in the submitted tasks.just to be clear for others who may be reading this, the order of submission is controlled by the queue implementation (where submission is the movement of a Callable from a queue to a thread). once the Callables are passed to threads, their actual order of execution is undefined (where execution is the invocation of the "call" method).And not only that, but even if we knew that the order of execution were call1, call2, call3, that still doesn't tell us anything, since there's no synchronization here, and hence any thread can be swapped out at any time. Call1 could be entered, but then swapped out before it gets to print anything, etc.
Bottom line: When you're dealing with multiple threads, unless you use synchronization, wait, notify(All), or higher level java.util.concurrent constructs, you have no ability to control or predict what executes when.

Similar Messages

  • Difference between Callable Object for execution and Display

    Hi,
             I am new to Guided Procedures.When i am creating a callable object under an Action ,i find callable object for execution and callable object for display in the dropdown.What is the difference between the two types of callable objects.
    Thanks,
    Bala

    Hi Bala,
    GP comes with a set of registered callable object types that define which applications you can directly expose as callable objects and enable their handling in the context of GP processes.
    So the different COs can handle your specific application requirements or process flow requirements appropriately at runtime.
    You refer those COs in actions. To make the action functional, you attach at least one callable object to it. In addition to the object that is executed when the action is called, you can attach a callable object that is displayed after the execution. The first one is mandatory. You must attach a callable object for execution. It can be either a callable object with a visible part, such as a Web Dynpro or BSP callable object, or one for background execution.
    Optionally, you can attach a callable object for display. It is required to have a visible part – for example, you cannot select a callable object for background execution.
    At runtime, this object is displayed if the processor wants to open the process step after it has been completed, or if a process contributor has view permissions on the action.
    To make it easier, I will give you an example with submitting and approving a composite form. Say, the employee fills in an order for something, submits it and the manager then approves or rejects it.
    First, in order for the employee to view the form, you can use a Form Display callable object as a display callable object for actions where the execution object is a form. It displays the name and description of the form and provides a link for download. If the user has view permissions on the step, he or she can view the display object and download the form itself. So, this CO is connected basically with the user experience and what he/she sees displayed on the screen, no matter what happens in the background (e.g. you can have a pre-filling service in the background that prefills some fields of the form, but what the user sees is only the form fields with certain info already prefilled in them).
    Next, for the manager to approve or reject the form of the employee, you need a CO that is only for execution, for example a Process Control CO for File Approval For forms, you can use it in a process in which a form is sent by e-mail. As soon as the form is submitted back to the system, the receiver can view it, save a copy of the form, and depending on his or her decision, can approve or reject it.
    This really is a very simplified example, but I hope it helped a little in some way or another
    Here is a link to the Callable Objects in GP documenatation, hope it also clears up some questions:
    http://help.sap.com/saphelp_nw70/helpdata/en/d2/d174413aff5458e10000000a1550b0/frameset.htm
    Also, a link to the documentation for exposing COs:
    http://help.sap.com/saphelp_nw70/helpdata/en/08/d88041a17e060de10000000a1550b0/frameset.htm
    HTH:)
    Greets,
    Petra

  • Cannot load callable object container: null

    My application is webdynprojava application with GP process.
    One of my scenaio was to create a popup window with ok button after completed the action.
    First I tried from code where i was written to completd the action
    but it did not work because the popcode i was writing before the complete method but it always talking after
    completeso results i was getting error .
    Then for the same action i created one callable object for display.
    That time my application was working after some time I again check
    then its showing    Cannot load callable object container: <null>
    this error for the callable object  which I created for popup window with ok button.
    (once RM will approve ,popup window will come with ok button ).
    Reporting Manager CO                    Callable Object for Execution   
       Resignationmanpowerlink                Callable Object for Display    --I am getting error here
    can u please help me why i am getting    Cannot load callable object container: <null>
    error
    Thanks for your time.
    Thanks & Regards.
    Abhishekh Singh

    Last time I checked contexts and lookups could return null values. And your code is not checking for a null value return.

  • Implementation callable object for background execution

    Hi experts,
    I am Using NWDS 7.0
    while i am trying to create background execution callable object , i didnt find the DC :caf/eu/gp/api.
    so i followed the pdf "How to Get NW04s SP7 Guided Procedure APIs for Local Development" and added the required DC's.
    The problem is that while i am selecting the  dc "caf/eu/gp/api"   the following message is displaying
    "illegal dependency: Acess list does not allow use of sap.com/caf/eu/gp/api for sap.com/bckg_co(MyComponents
    Is there any other way to add DC's ?
    pls help me out
    Thanks in advance
    kiran

    Hi Kiran,
    1. go to development Infrastructure --> select ur Software component --> in the component properties Tab > select dependencies Tab->click on Add Button.
    2. in the pop up window , select the Software component (Gp - Core) which has the  caf/eu/gp/api component and give the dependency details and click Finish.
    3. Ensure that Unrestricted acesss is granted for this component. this u can check, by selecting  caf/eu/gp/api  and select permissions tab in component properties.
    hope it helps,
    Thanks and Regards

  • Problem in Business Logic Callable Object execution

    Hi All,
    We are working on a workflow scenario where 2 approvals are present. Second approval is optional.
    Second approval is required or not is decided by a business logic callable object.
    This callable object is assigned (user role0 to initiator.
    Issue is, when first approval is completed, flow goes to business logic callable object. A UWL entry comes in initiators inbox. And from there, flow doesn't move forward. It simply shows message 'The next activity is not yet available: try again later using the "Refresh" button".
    I have tested this business logic callable object individually, and it works fine.
    But in process, it doesn't move further.
    What can be the solution to this?
    Thanks,
    Deepti

    Hi,
    I have the similar issue.
    In my case it is taking too much time for completion.
    It is a background step so it should execute automatically.
    I have also checked Queue's for this.
    But could not understand why it is taking soo much time?
    Regards,
    Pratik

  • Can't able to create callable object using UI pattern in CAF

    Hello
    I made one interface using object Selection UI pattern for one of my entity services. Now i am trying to make a callable object using this and i also have been successfully created it. But when I test this callable object, I got these error messages.
    1. Could not load execution container: Cannot access object class loader for deployable object sap.com/cafcoregpuivisibleco~container.
    2. Could not load execution container: ComponentUsage(container): Active component must exist when getting interface controller. (Hint: Have you forgotten to create it with createComponent()? Should the lifecycle control of the component usage be "createOnDemand"?
    Please tell me the problem

    Hi Saurabh,
    It seems you found a bug. The problem is that runtime library reference to sap.com/cafruntimeuicouplingapilib library from sap.com/cafcoregpuivisibleco~container dc is misspelled.
    So, I don't know whether or not according CSN is already created but I can propose you a solution.
    1. Unpack the cafcoregpuivisibleco~container archive from CAFKM0X_0.sca sca.
    2. Unpack sap.comcafcoregpuivisiblecocontainer.wda archive.
    3. Open the PORTAL-INF\portalapp.xml file and change the following entry of library reference:
    <property name="LibrariesReference" value="sap.com/cafruntimeuicopulingapilib" />
    to
    <property name="LibrariesReference"    value="sap.com/cafruntimeuicouplingapilib"/>And pack
    it pack it again in correct order(for ex.:
    jar.exe -Mcvf sap.comcafcoregpuivisiblecocontainer.wda .
    jar.exe -Mcvf sap.comcafcoregpuivisiblecocontainer.sda .
    And finally deploy it to your server instance and enjoy.
    Best regards,
    Aliaksei

  • Callable Objects-Write to System Log,Offline Approval

    Hi,
    I am new to Guided Procedures and I am trying out examples in all callable objects.
    I have doubts in 2 callable object
    1. Can you guide me how to use the callable object under Miscellaneous Type - Write to system Log
    After we Enter the Log text where to go and view the text.    
    2.Callable object under  Process control type -  OfflineApproval           
    When I use this callable object I am not getting mail whether the action is approved or rejected.
    Regards,
    Bala Baskaran
    Edited by: Bala Baskaran on Feb 27, 2008 12:45 PM
    Edited by: Bala Baskaran on Feb 27, 2008 12:48 PM

    Hi,
    Which SRM version are you working??Always mention that in your post for appropriate solutions.
    Pls see the foll notes:
    <b>Note 928320 - RBBP_OFFLINE_EVAL: Local purchase orders not selected</b>
    Note 980963 - RBBP_OFFLINE_EVAL: Some users not found
    Note 1039869 - RBBP_OFFLINE_EVAL:Sometimes text contains no Object ID
    1035114 - RBBP_OFFLINE_EVAL: Wrong messages , missing values there
    BR,
    Disha.
    <b>Pls reward points for useful answers.</b>

  • Exposing Web Services as Callable Objects

    Hello!
    I have SAP NetWeaver 04s SP7. How can I expose Web Services as Callable Objects?
    According to "Exposing Web Services as Callable Objects" (http://help.sap.com/saphelp_nw2004s/helpdata/en/44/4758351fcb1193e10000000a155369/frameset.htm), I should start with choosing type of CO "Service -> Web Service".
    Actually, I haven't this entry in CO type list!
    According to integrate Web Services with GP, this type appeared in SP8. What are the alternatives in SP7?
    "Background execution" and "External service" seem to be the best candidates...
    What is the best solution?
    Thanx in advance!

    Hello, Jan!
    I have SAP NWDS 7.0.07, and I cannot find there an option to create a CAF project. I can create Web service, EJB, Web DynPro, and something else - but not a CAF project. In documentation I did not find the connection points between NWDS and External Services, except some plug-ins.
    Maybe I've misunderstood you, sorry - I'm a newbie in SAP
    Actually, I've made a simple EJB, created a Web service from it, and deployed the WS to portal. Maybe, EJB instead of Web service can be somehow used in CAF?
    I've tried to create a CO of type Composite Application Service, but there was necessary to configure endpoint aliases. I've read the manual "Configuring Endpoint Aliases", but didn't succeed to make one for EJB remote call... I've defined the name, URL (http://<host_of_portal>:<portal_port>), user and pwd - but I've got an exception when tried to use the created alias:
    com.sap.caf.core.gp.servicelocator.exception.MetaModelBrowserException: Exception while trying to get InitialContext. at com.sap.caf.core.gp.servicelocator.CAFMetaModelBrowser.getAllApplications(CAFMetaModelBrowser.java:77) at com.sap.caf.core.gp.ui.backgroundco.admin.VSelect.browseCAFCore(VSelect.java:305) at com.sap.caf.core.gp.ui.backgroundco.admin.VSelect.onActionSelectEptAlias(VSelect.java:750) at com.sap.caf.core.gp.ui.backgroundco.admin.wdp.InternalVSelect.wdInvokeEventHandler(InternalVSelect.java:287) at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87) at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67) at
    Maybe, the easiest way is to upgrade the versions of SAP and NWDS?
    Are there some manuals that could provide me some help about:
    1) creating CAS from the deployed Web service (from its creation in NWDS till its use in CAF, step-by-step)
    2) binding Web Dynpro apps and Web services, using CAF and GP.
    Or maybe I should attend SAP courses?
    I have SAP NetWeaver 04s SP7 and NWDS ver. 7.0.07.
    Sorry for the messy post, I did my best
    Message was edited by:
            Kirill Shepitko

  • Model Execute Exception in a WD Callable Object

    Hello,
    I've been having some trouble making queries to a database through a Web Dynpro Development Component (GP Interface). I imported a Web Service and the calls are being made through there. I know that the Web Service works just fine as I've tested it through the WS Navigator. The problem occurs when I create the Callable Object and try to test it. The following message shows up:
    WDWSModelExecuteException: Exception on execution of web service with WSDL URL 'http://server:50000/LetterStep34WS/letter34?wsdl' with operation 'getLetterById' in interface 'LetterStep34WSVi_Document'
    I've tried redeploying the project, re-importing the web service model, and changing the package name where the model is imported but nothing seems to be working. Does anyone have any ideas? It´s becoming a pressing matter.
    Thanks,
    Luis T.

    Felipe,
    Check name of component used in Component Usage or in code: com.polar.excel.WDC_ExcelExport.
    Seems that you mistyped the name.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • How to create a WD4VC callable object in GP

    Hi Guru's;
    I want to use a WD4VC callable object in GP , can any one tell how to configure . I tryed the link given below
    http://help.sap.com/saphelp_nw70/helpdata/EN/44/5d5634cae308f9e10000000a422035/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40bfb641-9575-2a10-4794-e5f23ff06b4f
    but its not working. i am using verson 7.0 SP 13
    My task is to pass parameter form VC to GP.
    Please help me in that task
    Regards
    Vivekananthan.s

    Hi,
    you can look at this (from help.sap.com) (not sure if it works for 7.0):
    You can expose composite views created in Visual Composer as callable objects in the Guided Procedures design time, and then attach the callable object to an action in a Guided Procedures process flow. In Guided Procedures, these Visual Composer applications are called Web Dynpro for Visual Composer (WD4VC) Application callable objects. More information: Exposing WD4VC Applications as Callable Objects.
    Following are some general guidelines for modeling composite views for use as WD4VC application callable objects in a Guided Procedures process flow:
    Each WD4VC application callable object that passes data to and from Guided Procedures should contain at least a Start Point and an End Point, or a Data Bridge and an End Point depending on the use case:
    ¡        Use a Start Point and End Point when the dataset is flat and there is no semantic relationship between the fields. For example, if the dataset includes a customer ID field and a purchase order ID field
    ○       Use a Data Bridge in any of the following situations:
    ■       The dataset is clustered.
    ■       The dataset is flat, but there is a semantic relationship between the fields. For example, if the dataset includes an address consisting of 10 fields (such as street, zip code, country, and so on).
    ■       The structure of the dataset is based on a Web service, RFC, or similar.
    More information: Transferring Data Using a Data Bridge
    ·        Add an end point to each WD4VC application callable object to terminate the application.
    ·        A WD4VC application callable object that does not pass any data to Guided Procedures does not need a Start Point or a Data Bridge, it only needs an End Point.
    ·        In a WD4VC application callable object that uses a Data Bridge to communicate with Guided Procedures, and the component terminates with result states, you should model the mapping lines to the Data Bridge with the same events that are used to trigger the End Point connectors.
    ·        In a WD4VC application callable object that uses a Data Bridge to communicate with Guided Procedures, a Start Point can be used to initialize the application (and not to pass data to Guided Procedures).
    best regards,
    v s
    Edited by: v s on Jul 3, 2008 2:26 PM
    Edited by: v s on Jul 3, 2008 2:26 PM

  • Sending my callable object as interactive form thru workflow for approval

    hai
            I have created a sales order form as per the requirement given by sales head.Also i ve created a role in portal and have deployed my application implementing the rfc s required. i need to send my callable object(component1) to the saleshead with approve and reject button where when he approves notification mail should be sent to the required persons and if he rejects it should come back to me.(order initiator).i need to complete this soon and i dont have any idea about _+sending my callable object as interactive form thru workflow+_ .plz guide me with the steps(step bye step process) to be followed which ll help me to complete this project.

    Can we know the reason why do you need to extract the Interactive Form from Workflow.When you are calling the workflow try to save the form in a shared folder and save the url of the shared folder in a field and try to acces it by using SAP Activity.You can create a button for that create an SAP activity and when you click on the button the Interactive Form can be opened.
    Iam not sure weather i have answered your question or not?

  • How to change the order of execution

    How to make a table driving table in the list of joining tables in the from clause?
    for
    select count(1)
    from
    table_a a , table_b b , table_c c
    where a.col1=b.col1
    and b.col2 = c.col2
    I know that we can use ordered hint to make oracle the use the ordered mentioned in the from clause.
    How about joinng order in the where clause.
    Do I need to give any extra hints.
    I understand a bit of checking oracle execution path.
    Is there any material which can give me insight of the same.
    thanks in advance

    Hi,
    hints should be used when there is no way to obtain a correcte execution path having objects analyzed and properly setup.
    In that case, the /*+ ORDERED */ hint after the SELECT clause forces the execution plan to follow the execution order based on the FROM clause.
    Be aware that, if if You have more than 2 tables in the from clause, You can have a Cartesian Product if the from clause is not properly set.
    Hope this helps
    Max

  • How to enforce order of execution of parallel tasks?

    How do I set the order of execution of parallel tasks in a container?
    The execution isn't truly random. It appears to be set to a random constant at package creation.
    Demo
    I set up a dummy package.
    Max concurrent executions = 1
    sequence container with four script tasks that do a thread.sleep
    The tasks always execute in the order 4, 2, 1, 3. Closing/opening the solution makes no difference to the order of parallel execution.
    Is there a way i can change the execution order? Do I need to change the guid/id of the object (tried this but it invalidates the xml) or is there an order somewhere else in the XML?
    I've found a hack/workaround but it's a bit ugly so I'm wondering if there's a way to do it without adding dummy tasks.
    Basically if i create a dummy start task and then drag off "on success" constraints to each of the four threads, the threads will execute in parallel in the order in which i created the constraints
    Why do i want to do this? I have a number of parallel tasks in a sequence container where three will take a long time and the rest won't take as long.
    I'll minimise the time required for the execution of container by using parallel tasks AND controlling the queue order (longest first). It won't matter whether I have 1 logical cpu or as many logical cpus as i have tasks.
    Thanks
    Jakub @ Adelaide, Australia

    I think the problem you are trying to say is 
    a) You have multiple tasks( i assume 10) now out of these 3 execute slowly.
    b) You done have any constraints for task execution, so what you want to achieve is that the 7 task should continue without waiting for the other 3 in your case the 3 are starting up earlier and other 7 are not able to start as a result.
    AS arthur pointed out these are 2 diff things constraints and parallel execution, and there would always be some task which would be started at some point of time.
    But if you know in advance some tasks are going to take time, i would suggest keep 2 diff sequence containers in 1 keep the 7 tasks which runs fast in another one keep the other 3 which tend to run slow
    Abhinav http://bishtabhinav.wordpress.com/

  • Life cycle of a web dynpro callable object

    What is the life cycle of a web dynpro callable object.
    Means when that Web dynpro callble object is used in a GP process which method of that component called first and what is the sequence of the method execution in that.
    Can anyone please explain me.

    Sorry ritu there was one mistake in the above two replies.
    The actual execution of the methods when a callable objects is get executed is as following
    1.component controller's  init() method
    2. interface's  init() method
    3.view's  init() method.
    4.interface's execute() method
    5.view's wDoModifyView() method.
    If you want to change anything on your view according to the change in the interfac's execute method.
    Then you have to do that coding in view's wDoModifyView() method.
    with regards
    shanto aloor.

  • Callable Object for Webdynpro Application

    Hello,
    I have  a Webdynpro for Java Application where I am importing a model from R/3 and displaying certain records......and want to include it in GP Framework....so which is the Callable Object I should use.....i tried using Webdynpro application type but it gives me the error at runtime while execution as :
    Application error occurred during request processing.
      Details:   com.sap.tc.webdynpro.services.sal.core.DispatcherException: Failed to start deployable object sap.com/home~<webdynpro component name>
    Any help would be highly appreciated.
    Regards,
    Anil

    Hi Anil,
               I am also facing a similar problem . Can you please guide how to solve it.
    Thanks and Regards,
    Anurag

Maybe you are looking for

  • How to create a new page as a hyperlink to an external one?

    I've been trying to solve this for like 2 hours and still haven't found the way! When you create a new page in iWeb, it automatically adds its name into the navbar and creates a new page and folder with its content. Well, I want to create a new page

  • How do I get ios6 back on my iPhone 5?

    I just downloaded ios 7 on my iPhone 5 a few days ago and I am extremely dissatisfied for many reasons. I love the look and ease of use that I experienced with ios 6, however, after doing some research on the internet, I can't find a way to downgrade

  • Re-sizing Macintosh HD 2 Partition

    While trying to install OS X I had to partition my hard drive in to 2 disks, because the OS wouldn't install onto the first disk. So now I have it running fine on Macintosh HD 2, which is at 123.95GB, but I have 125.12GB of space on the first disk th

  • Stuck on rotated screen view

    Hi, You know how when you rotate your ipod, it changes the screen view to the sideways one? Well my ipod is stuck on that side screen display for my music and internet browser and so I can't get back to my playlists to choose what I want to listen to

  • Supressing blank rows

    Hi I'm sure the answer is already here, but I've been looking for two days and I can't find it. I have a master table where one of the columns is a check box. I would like to copy all rows where the check box is ticked to a slave table so that I can