IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
  • 1.  Java service multi threadInvoke

    Posted Thu June 20, 2019 10:09 PM

    Hi All,

    Need help here. I’m just new to WM java service. I might made some mistakes along the code.
    I wanted to create a java service that would spawn a number of threads depending on the number of input parameters, each input will do a server.doThreadInvoke to a certain flow service that will have some processing. During the implementation it keeps on throwing an error execution.

    Input:
    inputParam ----> string array

    Output:
    documents -----> documentArray

    IDataCursor pipelineCursor = pipeline.getCursor();
    String inputParam= IDataUtil.getStringArray( pipelineCursor, “inputParam” );
    pipelineCursor.destroy();

    ServiceThread svcThread = null;
    for(int i=0;i<inputParam.length;i++){
    IData input = IDataFactory.create();
    IDataCursor inputCursor = input.getCursor();
    IDataUtil.put(inputCursor, “inputToService”, inputParam[i]);
    inputCursor.destroy();
    Logging(“DEBUG”,inputParam[i]);
    svcThread[i] = Service.doThreadInvoke(“helloFolder.anotherFold.services”, “ServiceMade”, input);
    }
    Logging(“DEBUG”,“reached this point”);
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    for(int i=0;i<=inputParam.length;i++){
    try {
    documents[i] = IDataFactory.create();
    IDataCursor docCursor = documents[i].getCursor();
    IDataUtil.put( docCursor , “documents”, svcThread[i] );
    docCursor .destroy();
    } catch (Exception e) {
    throw new ServiceException(e);
    }
    }
    pipelineCursor_1.destroy();

    I get to see the logging of the inputParam[0]. (invoked service contains logging). however, I can’t see if it was able to process the inputParam[1] and so on. because I can’t see their process in the logs. My guess is that during the first invocation, inputParam[0]. it was able to successfully invoke the service but after the invocation, there’s some error.

    I get a null pointer error at the first loop (it doesn’t reach the second loop) because I’m not seeing “reached this point” in the logs. Is there any step that I’m missing.

    Error
    java.lang.NullPointerException
    at helloFolder.anotherFold.services.ServiceMade(services.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: Java service multi threadInvoke

    Posted Sat June 22, 2019 03:17 AM

    May I know the reason for this service and also your wM version?

    There is a service already available “pub.flow:invokeService”, check the service guide.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 3.  RE: Java service multi threadInvoke

    Posted Sat June 22, 2019 03:31 AM

    You’re trying to access svcThread before it’s initialized.

    Try to change the code below:

    ServiceThread[] svcThread = null;

    to

    ServiceThread[] svcThread = new ServiceThread[inputParam.length];

    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 4.  RE: Java service multi threadInvoke

    Posted Sun June 23, 2019 11:34 PM

    @Mahesh, I wanted to create a service that would accept an array input. These array input will looped inside the service and each input will spawn a new thread and invoke a service. This way I would be able to asynchronously invoke services, then take the output of each spawned thread and output it as the output of the service.

    @Xiaowei Wang, Thank you for this. This solved my problem. :slight_smile:


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 5.  RE: Java service multi threadInvoke

    Posted Mon June 24, 2019 04:27 AM

    @ Mark,

    Thanks for the details, just thinking what would be the ideal use case to spawn the thread based on number of inputs?

    We have used a code which invokes the service purely in async fashion and continues with the next execution, I am curious to know your requirement.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: Java service multi threadInvoke

    Posted Mon June 24, 2019 04:48 AM

    Hi @Mahesh,

    Actually, I have a service that outputs an array of string. Then each string is an input of the invoked service, since the backend of the invoked service might respond for more than a second, invoking the service synchronously for each input string might take me forever(e.g. string might have a length of 50). Then taking the response of each of the invoked service( so that could be a document array of 50 ) for further processing.

    E.g. Service Response = inputParam[0] = input_1, inputParam[1]=input_2, inputParam[2]=input_3.
    So I need to invoke “helloFolder.anotherFold.services:ServiceMade” 3x asynchronously.

    And read some posts from the forum, their talking about service.doThreadInvoke() and getIData(). So I was thinking of using them with some for Loop logic.

    hmmm… Do you mean pub.flow:invokeService can invoke other service Asynchronously? The documentation seems to be confusing.

    Thank you. I would like to get some suggestions If you could provide. I really wanted to avoid java service if possible.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 7.  RE: Java service multi threadInvoke

    Posted Mon June 24, 2019 05:06 AM

    pub.flow:invokeService is not Async, I can crosscheck again.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 8.  RE: Java service multi threadInvoke

    Posted Mon June 24, 2019 05:33 AM