Unable to invoke Two services parallelly from java service

Hello Team,

I am trying to invoke two flow services parallelly using java ExecutorService But it is not happening.

Would you please let me know here I am going wrong.

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String message1 = IDataUtil.getString( pipelineCursor, “message1” );
String message2 = IDataUtil.getString( pipelineCursor, “message2” );
pipelineCursor.destroy();

	//Input 1
	IData input = IDataFactory.create();
	IDataCursor inputCursor = input.getCursor();
	IDataUtil.put( inputCursor, "message",message1 );
	inputCursor.destroy();
	
	//Input2
	IData input1 = IDataFactory.create();
	IDataCursor inputCursor1 = input1.getCursor();
	IDataUtil.put( inputCursor1, "message2", message2 );
	inputCursor1.destroy();
	
	Callable callable1=new Callable(){
		@Override
		public Void call() throws Exception{
			try{
				Service.doInvoke( "javaServicePoc.services.SyncCall", "publisher1", input );
			}catch( Exception e){
				throw new ServiceException(e);
			}
			return null;
		}
	};
	Callable callable2=new Callable(){
		@Override
		public Void call() throws Exception{
			try{
				Service.doInvoke( "javaServicePoc.services.SyncCall", "publisher2", input1 );
			}catch( Exception e){
				throw new ServiceException(e);
			}
			return null;
		}
	};
	List<Callable<Void>> taskList=new ArrayList<Callable<Void>>();
	taskList.add(callable1);
	taskList.add(callable2);
	ExecutorService executor=Executors.newFixedThreadPool(2);
	try
	{
		executor.invokeAll(taskList);
		executor.shutdown();
	}
	catch(InterruptedException ie){
		throw new ServiceException(ie); // getting error here
	}
			
}

Thanks in Advance

Hi Mukesh,
It would be a good idea to explain what you mean by “it is not happening”. However, I can already guess.
The issue is that you cannot fire a service in a separate thread in this way. If you want to run services they have to belong to a Service thread and not a generic java thread.

You need to trigger threads from the service thread pool i.e.

Service.doThreadInvoke(ns, service, inputPipeline, maxWait);

ns is the folder hierarchy or namespace.
service is the name of the service.

Hello @John_Carter4 ,

I got it.

Thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.