|
From: McDonald, B. <Bru...@ba...> - 2003-07-28 20:59:25
|
Please submit this Stefan.
-----Original Message-----
From: Stefan Krieger [mailto:ste...@co...]
Sent: Monday, July 28, 2003 4:56 PM
To: bab...@li...
Subject: [Babeldoc-devel] Synchronization problem in GenericSQLJournal
Hello,
We are using the SQL journal in a multi-threaded J2EE environment and got
some DB error, because of duplicated IDs in LOG table.
We solved it by making getNextStep and the DB Update a critical section. I
think, this makes sense and should go into the babeldoc code.
Regards,
Stefan
// copied from GenericSQLJournal with synchronization
// getNextStep + DB Update is a critical section
protected void log(IJournalTicket ticket, JournalOperation operation,
String other, String stage, Object data) throws
JournalException {
//getLog().debug("[GenericSqlJournal.log] called");
// Get the next step for the ticket
if (!ticket.isDummy()) {
PreparedStatement pstmt = null;
Connection con = null;
String logInsertStmt = SqlQueryManager.getSqlQuery(LOG_INSERT);
//getLog().debug("[GenericSqlJournal.log] sql: "+logInsertStmt);
long id = ((JournalTicket)ticket).getValue();
try {
con = (Connection) resource.checkOut();
pstmt = con.prepareStatement(logInsertStmt);
String pstageName = (stage != null) ? stage : "null";
String additional = "";
if (operation.equals(JournalOperation.updateStatus)) {
additional = (String) data;
}
//getLog().debug("[GenericSqlJournal.log] Writing step: "+step);
pstmt.setLong(1, id);
pstmt.setLong(3, new java.util.Date().getTime());
pstmt.setString(4, operation.toString());
pstmt.setString(5, other);
pstmt.setString(6, pstageName);
pstmt.setString(7, additional);
long step ;
// without synchronized it is likely to get the same value
// from getNextStep several times in multiple threads
synchronized ( this.getClass() ) {
step = getNextStep(con, id);
pstmt.setLong(2, step);
pstmt.executeUpdate();
}
if (operation.equals(JournalOperation.updateDocument)) {
writeDelta(con, id, step,
(com.babeldoc.core.pipeline.PipelineDocument) data);
}
} catch (Exception se) {
LogService.getInstance().logError(se);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
resource.checkIn(con);
} catch (Exception se) {
LogService.getInstance().logError(I18n.get("sql.403"), se);
}
}
}
}
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Babeldoc-devel mailing list
Bab...@li...
https://lists.sourceforge.net/lists/listinfo/babeldoc-devel
|