[jboss-user] [JBoss jBPM] - Re: How to best control access from multiple threads to a Pr

jse do-not-reply at jboss.com
Tue Dec 16 10:55:40 EST 2008


AmiraTalbi

You exactly understand the problem... and you are right, it is not specifically a jBpm issue. There is a resource (the process instance) that needs to be "used/updated" by each thread in turn, not all at once.

The reason I did not want to use your suggestion is that I think that this would block all traffic... In 60 seconds I may have 1,000 incoming events/threads, destined for 950 different process instances. In the vast majority of cases there is no contention and i could, in theory, process 950 process instances in parallel... with only 50 blocking.

The only solution that I can think of is to either use the jBpm lock facility OR to have an external locking process.
1) Using the jBpm lock facility

  | 		long pid = 123; 
  | 		JbpmContext jC = jbpmConfiguration.createJbpmContext();
  | 		try {
  | 			ProcessInstance pI = jC.loadProcessInstanceForUpdate(pid);
  | 			pI.getRootToken().lock(Thread.currentThread().toString());
  | 		}
  | 		finally {
  | 			jC.close();
  | 		}
  | 		try {
  | 			ProcessInstance pI = jC.loadProcessInstanceForUpdate(pid);
  | 			pI.getRootToken().unlock(Thread.currentThread().toString());
  | 			pI.signal();
  | 		}
  | 		finally {
  | 			jC.close();
  | 		}
  | 
The problem with this is it is pretty heavyweight (in terms of database updates done) and also I have to write a fair chunk of code to deal with threads that die without releasing their lock etc etc etc.

2) Implementing a a lock facility using the database, for example mysql SELECT GET_LOCK('lock1',10)
The problem with this is that I need to ensure that no thread attempts to acquire a process instance without first getting a lock.

Unfortunately the solution is multi node, so I am not able to do in memory locking easily.

I had hoped that jBpm might have a clever way of achieving this without me having to write any code.  At an abstract level I believe that this problem is similar to a process instance reaching a task node whose task could be performed by multiple actors. Presumably in this case jBpm has some mechanism to prevent multiple actors fulfilling the task.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4196919#4196919

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4196919



More information about the jboss-user mailing list