# Unable to invoke Two services parallelly from java service

**URL:** <https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919>\
**Category:** Forum\
**Tags:** flow-service, java-service, thread\
**Created:** [November 12, 2022, 1:23pm UTC](https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919 "2022-11-12T13:23:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mukesh.b.behera](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/mukesh.b.behera/32/34097_2.png) [@mukesh.b.behera](https://techcommunity.softwareag.com/u/mukesh.b.behera)\
**Post date:** [November 12, 2022, 1:23pm UTC](https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919/1 "2022-11-12T13:23:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Carter4](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/john_carter4/32/19818_2.png) [@John\_Carter4](https://techcommunity.softwareag.com/u/John_Carter4)\
**Post date:** [November 14, 2022, 8:10am UTC](https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919/2 "2022-11-14T08:10:23Z")

</div>

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.

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

```

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

---

<div class="post-metadata">

**Author:** ![mukesh.b.behera](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/mukesh.b.behera/32/34097_2.png) [@mukesh.b.behera](https://techcommunity.softwareag.com/u/mukesh.b.behera)\
**Post date:** [November 15, 2022, 9:43am UTC](https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919/3 "2022-11-15T09:43:33Z")

</div>

Hello @John_Carter4 ,

I got it.

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [May 14, 2023, 9:44am UTC](https://techcommunity.softwareag.com/t/unable-to-invoke-two-services-parallelly-from-java-service/265919/4 "2023-05-14T09:44:04Z")

</div>

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