<div dir="ltr">I would use a transaction synchronization, so you don&#39;t spawn the other thread until the transaction is successfully committed.<div><br></div><div>What does the spec say about transactions? If a job is create in a thread that is part of a transaction and the transaction is rolled back should the job actually go ahead? Common sense would suggest not.</div>
<div><br></div><div>Stuart</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 4, 2014 at 4:49 PM, Cheng Fang <span dir="ltr">&lt;<a href="mailto:cfang@redhat.com" target="_blank">cfang@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div bgcolor="#FFFFFF" text="#000000">
    A jberet user reported
    
    <a href="https://issues.jboss.org/browse/JBERET-29" rel="12531044" target="_blank">JBERET-29</a> (Foreign key constraint
    step_execution_jobexecutionid_fkey fails when using Postgresql on
    WildFly, and we are trying to fix it by jberet 1.0.0.Final.  The
    problem happens when user app starts a job within a transaction
    (e.g., CMT EJB), jberet inserts JobExecution into database (thread 1
    &amp; transaction 1), and then spawn a jberet-batch thread to run
    the job (thead 2 &amp; transaction 2).  Sometimes T2 tries to access
    db before T1 is committed, hence the error reported by the user.<br>
    <br>
    What&#39;s the common approach for solving this kind of problem?  I
    suppose other WildFly components may also have this issue and
    probably already solved.  Using transaction synchronization is a
    cleaner solution than polling db, but I&#39;m not sure about its full
    implication.  Ideally, I don&#39;t want to use system level JTA API like
    TransactionManager or Synchronization in jberet proper, but probably
    we can implement it in WildFly jberet integration.<br>
    <br>
    Thanks,<br>
    Cheng<br>
  </div>

<br>_______________________________________________<br>
wildfly-dev mailing list<br>
<a href="mailto:wildfly-dev@lists.jboss.org">wildfly-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/wildfly-dev</a><br></blockquote></div><br></div>