我想知道是否有休眠延迟其写入数据库的可能性。我有配置为MySQL的休眠。我希望支持的情景是80%的读取和20%的写入。所以我不想优化我的写入,我宁愿让客户端等到数据库被写入,而不是稍后返回。我的测试目前有100个并行的客户端,cpu有时会最大限度地运行。我需要这种刷新方法立即写入数据库,并仅在数据写入时才返回。休眠延迟写
在我的客户端,我发送了一个写请求,然后发送了一个读请求,但是这个读请求有时会返回null。我怀疑hibernate没有立即写入数据库。
public final ThreadLocal session = new ThreadLocal();
public Session currentSession() {
Session s = (Session) session.get();
// Open a new Session, if this thread has none yet
if (s == null || !s.isOpen()) {
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
session.set(s);
}
return s;
}
public synchronized void flush(Object dataStore) throws DidNotSaveRequestSomeRandomError {
Transaction txD;
Session session;
session = currentSession();
txD = session.beginTransaction();
session.save(dataStore);
try {
txD.commit();
} catch (ConstraintViolationException e) {
e.printStackTrace();
throw new DidNotSaveRequestSomeRandomError(dataStore, feedbackManager);
} catch (TransactionException e) {
log.debug("txD state isActive" + txD.isActive() + " txD is participating" + txD.isParticipating());
log.debug(e);
} finally {
// session.flush();
txD = null;
session.close();
}
// mySession.clear();
}
花了我一些时间进行调试。 Mysql日志非常棒。所以这些是我调试的结果。如果我 – Siddharth 2012-01-16 05:14:44