Last active
October 1, 2015 23:58
-
-
Save atamanroman/2128169 to your computer and use it in GitHub Desktop.
Broken use of REQUIRES_NEW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
public class Importer { | |
@EJBContext | |
private EJBContext ctx; | |
private ConcurrentLinkedQueue queue = new ... | |
private AtomicBoolean isRunning = false; | |
public void add(ImportItem itm) { | |
queue.offer(item); | |
if(!isRunning) start(); | |
} | |
public void start() { | |
while(!queue.isEmpty()) | |
this.importItem(queue.poll()); | |
} | |
@TransactionAttribute(REQUIRES_NEW) | |
public void importItem() { | |
try { | |
// do some fancy xml stuff | |
} catch (Exception ex) { | |
ctx.setRollbackOnly(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EJB | |
private Importer thisBean; | |
public void start() | |
{ | |
while(!queue.isEmpty()) | |
thisBean.importItem(queue.poll()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment