database - 为什么我的数据库读取会阻止我的播放框架服务器?
问题描述
我有一个使用 AWS EC2 实例托管在 AWS RDS 和 Play 框架服务器上的 mySQL 数据库。我所有的其他 API 端点都工作正常,但是每次对我的数据库进行多个连接时,我的服务器似乎都会关闭一段时间。我做了一些研究,我认为这可能与线程池或请求被阻塞有关。这是我的操作代码:
def getDataFromDB = Action {
val conn = db.getConnection()
var qJsonArray: JsArray = Json.arr()
try {
val stmt = conn.createStatement
val query = "SELECT * FROM table"
val rs = stmt.executeQuery(query)
val rsmd = rs.getMetaData
val columnCount = rsmd.getColumnCount
while (rs.next) {
var index = 1
var rsJson: JsObject = Json.obj()
while (index <= columnCount) {
val column = rsmd.getColumnLabel(index)
val columnLabel = column.toLowerCase()
val value = rs.getObject(column)
if (value == null) {
rsJson = rsJson ++ Json.obj(
columnLabel -> JsNull
)
} else if (value.isInstanceOf[Integer]) {
rsJson = rsJson ++ Json.obj(
columnLabel -> value.asInstanceOf[Int]
)
} else if (value.isInstanceOf[String]) {
rsJson = rsJson ++ Json.obj(
columnLabel -> value.asInstanceOf[String]
)
} else if (value.isInstanceOf[Date]) {
rsJson = rsJson ++ Json.obj(
columnLabel -> value.asInstanceOf[Date].getTime
)
} else {
throw new IllegalArgumentException("oh no")
}
index += 1
}
qJsonArray = qJsonArray :+ rsJson
}
} finally {
conn.close()
}
Ok(qJsonArray)
}
解决方案
推荐阅读
- mercurial - 放弃 Mercurial 话题
- node.js - 通过 socket io 客户端连接到服务器
- javascript - JS - 每 5 秒显示一次 div,带有淡入淡出效果和关闭按钮
- php - 你会如何每 30 分钟循环一次
- reactjs - Chrome 开发者工具控制台不显示文件名
- android - 在 Android Studio 上查看布局时出现问题
- amazon-web-services - AWS Authorizer 请求标头为空
- javascript - 道具类型失败:提供给“TextInput”的“对象”类型的道具“值”无效
- linux - POSIX中的`write`序列化
- html - html 文件 src 路径错误和 404 未找到