In our environment, we get a high volume of messages from a queue and handle them asynchronously. For each message we need to create or lookup a row in the database. We're following a typical create-get pattern to handle issues where two threads are addressing the same "parent" object:
public void ensure(Data d) {
try {
o = dao.create(d);
log("Created");
}
catch(Exception x) {
o = dao.get(d);
if(o != null) {
log("Existed");
}
else {
event("Couldn't create or get parent!");
}
}
}
This works 100% of the time. I always see the expected objects in the database and never see the "Couldn't create" message. Excellent.
The ugly part about this is that even though the exception thrown from the create when the object already exists is caught and handled, I still see the exception in the logs, which understandably creates some confusion:
[7/16/15 11:11:37:930 EDT] 0000003b RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: <openjpa-2.1.2-SNAPSHOT-r422266:1636464 fatal store error>
org.apache.openjpa.persistence.EntityExistsException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
<Exception stacktrace omitted>
[7/16/15 11:11:37:942 EDT] 0000003b SystemOut O Existed
Sorry, I can't post the entire stacktrace due to security issues.
Any idea how I can get this phantom exception to stop showing up in the logs?
Aucun commentaire:
Enregistrer un commentaire