cancel
Showing results for 
Search instead for 
Did you mean: 

how can I force a commit inside java task

jcosano
Champ in-the-making
Champ in-the-making
I have this code (belongs a java task execution method)

   
while (it.hasNext())
{
   value = it.next();
   startProcessInstance(value);
   timer= (String)value.get("tumod");
   execution.setVariable("LAST_TIMER", timer);
**** FORCE COMMIT HERE  😄 ****
}

I have a loop, that creates process instances…  and I would commit in each loop for save last_timer, then if one startProcessInstance fails, next time, process start from a good last_timer, and not duplicate process instances.

Question is, can I force commit?
I try with:

context.getDbSqlSession().flush();
context.getTransactionContext().commit();

But only works in first iteration…
5 REPLIES 5

jcosano
Champ in-the-making
Champ in-the-making
Ok…

for now is working:


while (it.hasNext())
{
value = it.next();
startProcessInstance(value);
timer= (String)value.get("tumod");
execution.removeVariable("LAST_TIMER");
execution.setVariable("LAST_TIMER", timer);

context.getDbSqlSession().flush();
trans.commit();

}


This process is a starter process that every 10 minutes launch a lot of process instances of process B.
If this process crash, The next time that is launched is mandatory that don't create duplicate process instances of B… and re-start from last save pointer (last_timer variable).

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
I'm not sure this is a good idea… I'm even pretty sure this is not a good idea. You in fact influence the engine itself and that might lead to unexpected behaviour sooner or later.

Since I'm not quite sure what you try to achieve besides starting processes from a process, I cannot give you other options.

jcosano
Champ in-the-making
Champ in-the-making
Ok, I'll try to explain.

I have a launcher process (A), with only 1 activity, that every 10 minutes, go to a database, recolect data from a last timer, and for each row, create a process instances of process B.
For me is important, that one row of database, creates only 1 process instance.

Then, sometimes there is a rollback when running process A, in this cases, timer is rollback, but all process instances of process B that was created previously are active.
Then, If i commit in each iteration, then I'm saving last timer, then if process A re-launch, process instances of B are not duplicated, because timer was updated.

I know that is nasty, but I don't known how can I keep transactionally between this two process.

jbarrez
Star Contributor
Star Contributor
What if you send a message from process A  (eg JMS - which is transactional), and start the process B when receiving this message ?

jcosano
Champ in-the-making
Champ in-the-making
Thanks! it is another way to explore !