I think i confused things a bit...
getTask was originally marked as REQUIRES_NEW and getNextTaskID was a POJO function. This half worked in that as getNextTaskID was the first thing to be called in getTask, it locks the row.
But you are right in that getNextTaskID need to be a EJB method and be declared as REQUIRES_NEW so that when it returns, it commits the transaction and releases the row lock so that the potentially long execution time of getTask doesn't block all the others.
Noting something you said before, does it matter if i use @EJB to get a reference to the beans interface or call SessionContext.getBusinessObject within the function in terms of performance?
Also, now i've noted another problem.
getNextTaskID is declared as an interface function and creates and commits its own transaction, and i return the object i fetch, however in the outer function the object is now detached. Is this expected? for example
@TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
public Task getNextTaskID(){
Task task=em.createNamedQuery("getID").getSingleResult();
task.setProcessing(true);
return task;
}
public void processTask(){
Task task=getNextTask();
// here em.contains(task) is false and any changes i make to task aren't committed
do_something_with(task);
}
[Message sent by forum member 'jsl123' (jsl123)]
http://forums.java.net/jive/thread.jspa?messageID=217968