【问题标题】:Datastax: Re-preparing already prepared query warningDatastax:重新准备已经准备好的查询警告
【发布时间】:2014-11-17 22:42:58
【问题描述】:

我有这个代码

    UUID notUuid = UUIDs.timeBased();        
    PreparedStatement   pstmt           = cqlSession.prepare("INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?)");
    BoundStatement      boundStatement  = new BoundStatement(pstmt);
    cqlSession.execute(boundStatement.bind(userId, notUuid, notfMsg, System.currentTimeMillis(), MigificConstants.UNREAD, "false"));

当我运行这段代码时,它会在日志中显示

Re-preparing already prepared query INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?). Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.

【问题讨论】:

标签: cql3 datastax-java-driver


【解决方案1】:

这段代码是被多次调用的方法的一部分吗?

每个集群实例只需要准备一次语句,您应该在应用程序的某些初始化部分进行。

【讨论】:

  • 是的,每次收到新消息时都会调用它。所以我应该只在应用程序开始时初始化cqlSession.prepare 行。这种说法我有很多
  • 是的。如果您使用某种 DAO 对象,那么在构造函数中执行此操作的好地方,然后使 DAO 成为单例。
猜你喜欢
  • 2018-09-21
  • 1970-01-01
  • 2018-09-26
  • 2012-12-07
  • 2014-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-16
相关资源
最近更新 更多