Interview Question
Qus: How to limit a flow service executed only by one thread at a time?
Answers (1)
- Create a java service
- Create a private static object on the shared source (private static Object LOCK_OBJ = new Object(); )
- Have the code below on the java service source:
IDataCursor idc = pipeline.getCursor();
IDataCursor idcResult = null;
try {
// put this section into a critical section to ensure single-threaded execution
synchronized(LOCK_OBJ)
{
Execute a flow service using Service.doInvoke
}
idc.destroy();
idcResult.destroy();