- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在为我正在创建的投注程序创建一个 Elo 系统,以比较两个竞争对手并确定投注金额。我超时收集了一些数据,需要对所有这些数据进行计算以收集 Elo 分数。
我有大约 1150 条记录需要执行此操作。我最初的方法是查询所有记录,然后使用 while(rs.next()) 对每条记录进行计算,然后使用另一个查询用新值更新表。但程序卡在我的更新语句上。它挂起的位置在下面的代码中用注释“//HANGS RIGHT HERE”标记。有趣的是,它没有给出任何错误或异常。它只是坐在那里,不会再进一步发展。我尝试了几种解决方案,但无法提出/研究解决方案。下面的代码代表了整个程序:
package elomaker;
import java.awt.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class EloMaker {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
//initial variables
Connection con;
Statement stmt = null;
Component frame = null;
String sqlPullFights = "select f.fid,\n"
+ " f.p1id,\n"
+ " f.p2id,\n"
+ " f.winner,\n"
+ " (select p.elo from players p where f.p1id = p.pid) p1elo,\n"
+ " (select pl.elo from players pl where f.p2id = pl.pid) p2elo\n"
+ "from fights f";
ResultSet rs = null;
int x = 0;
//initializing the database to make sure the datbase is ready.
String dbURL = "jdbc:oracle:thin:@localhost:1521:orcl";
String userName = "NEGGLY";
String password = "Yellow23";
try {
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(dbURL, userName, password);
stmt = con.createStatement();
} catch (ClassNotFoundException e) {
System.out.println("Couldn't register JDBC driver,");
System.out.println("Applicaiton Ending.");
System.exit(-1);
} catch (SQLException e) {
JOptionPane.showMessageDialog(frame, "Could not establish a connection to the database", "Database Error", +JOptionPane.ERROR_MESSAGE);
System.exit(-1);
}
//pull the fight values for each player
rs = stmt.executeQuery(sqlPullFights);
while (rs.next()) {
int intP1ID = rs.getInt("P1ID");
int intP2ID = rs.getInt("P2ID");
int intWinner = rs.getInt("WINNER");
int intP1Elo = rs.getInt("P1ELO");
int intP2Elo = rs.getInt("P2ELO");
int intP1NewRating, intP2NewRating;
double dblP1Outcome, dblP2Outcome;
dblP1Outcome = 1 / (1 + (Math.pow(10, (intP2Elo - intP1Elo) / 400)));
dblP2Outcome = 1 - dblP1Outcome;
//determine the winner
if (intP1ID == intWinner) {
intP1NewRating = (int) (intP1Elo + 32 * (1-dblP1Outcome));
intP2NewRating = (int) (intP2Elo + 32 * (0-dblP2Outcome));
} else {
intP2NewRating = (int) (intP2Elo + 32 * (1-dblP2Outcome));
intP1NewRating = (int) (intP1Elo + 32 * (0-dblP1Outcome));
}
String sqlUpdP1Rate = "update players set elo = "+intP1NewRating+" where pid = " + intP1ID;
String sqlUpdP2Rate = "update players set elo = "+intP2NewRating+" where pid = " + intP2ID;
stmt.executeQuery(sqlUpdP1Rate); //HANGS RIGHT HERE.
stmt.executeQuery(sqlUpdP2Rate);
stmt.executeQuery("commit");
x++;
System.out.println(x);
}
}
}
任何有关此问题的帮助将不胜感激。
最佳答案
当应用程序被阻止时执行此查询:
select /* +rule */
s1.username || '@' || s1.machine
|| ' ( SID=' || s1.sid || ' ' || s1.program || ' ) is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ' || s2.program
|| ' ) ' AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;
这将告诉您哪个 session 持有您正在等待的锁。
PS:也许使用 con.commit();
来提交您的交易。您也不应该跨提交获取。将提交放在脚本的最后(循环之外)。但无论如何,我认为 JDBC 连接默认启用了自动提交(尝试将其关闭)。
关于JAVA/Oracle SQL 因阻塞而挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21233359/
对于一个简单的聊天程序,我使用了一个通过 boost::python 包装的 c 库。 使用 PyQT 编写了一个简单的 GUI。接收消息是通过阻塞调用完成的lib说。对于独立刷新的 GUI,通信部分
当我创建以下内容时,我试图创建一个可以被异常终止的线程类(因为我试图让线程等待一个事件): import sys class testThread(threading.Thread): def
我正在用 Haskell 编写服务器,我想在客户端断开连接后显式关闭它们。当我调用 hClose ,线程将阻塞,直到客户端关闭其一侧的句柄。有没有办法让它在不阻塞的情况下关闭? 提前致谢! 最佳答案
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: garbage collection Operation 我有几个相关问题。 1.JAVA垃圾收集器运行时,是否占用
我有一个 Angular 函数,它在初始 URL 中查找“列表”参数,如果找到,就会出去获取信息。否则我想获得地理位置。如果存在 URL 参数,我不想获取地理位置。我使用的术语是否正确? constr
我读了很多关于锁定数据库、表和行的文章,但我想要较低的锁定,比如只锁定“操作”,我不知道如何调用它,假设我在 php 中有函数: function update_table() { //que
在我的多线程 mfc 应用程序中,m_view->SetScrollPos 处于阻塞状态并且所有应用程序都被卡住。 View 是在另一个线程中创建的,这是这种行为的原因吗? //SetScrollPo
FreeSwitch 软件在几天内运行良好(~3 - 5 天),然后由于 FreeSwitch 被阻止,新的来电请求被接受!!正在进行的调用继续他们的 session ,他们的调用似乎没有受到影响,但
我有一组按钮,当鼠标悬停在这些按钮上时,它们会改变颜色。这些的 CSS 以这种方式运行: #navsite ul li button { height: 60px; width: 60
由于某些原因,当我调用 WSARecvFrom 时,该函数在接收到某些内容之前不会返回。 _socket = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, N
我了解一些关于 Oracle 阻塞的知识——更新如何阻塞其他更新直到事务完成,写入者如何不阻塞读取者等。 我理解悲观和乐观锁定的概念,以及有关丢失更新等典型银行教科书示例。 我也理解 JDBC 事务隔
在两个代码点之间,我是否可以判断进程是否已被内核抢占,或者更确切地说,当时是否有任何其他代码在同一处理器上运行? //Point A some_type capture = some_capture(
这是我在 Oracle 的面试问题。 有一个堆栈,即使堆栈已满,push 操作也应该等到它完成,即使堆栈为空,pop 操作也应该等到它完成。 我们怎样才能做到这一点? 我的回答 让一个线程做push
我想知道是否有人可以告诉我如何有效地使用循环平铺/循环阻塞进行大型密集矩阵乘法。我正在用 1000x1000 矩阵做C = AB。我按照 Wikipedia 上的循环平铺示例进行操作,但使用平铺得到的
我正在阅读有关绿色线程的内容,并且能够理解这些线程是由 VM 或在运行时创建的,而不是由操作系统创建的,但我无法理解以下语句 When a green thread executes a blocki
我正在创建的 JavaScript API 具有以下结构: var engine = new Engine({ engineName: "TestEngine", engineHost
ChildWindow 是一个模态窗口,但它不会阻塞。有没有办法让它阻塞?我基本上想要一个 ShowDialog() 方法,该方法将调用 ChildWindow.Show() 但在用户关闭 Child
我需要一些关于如何调试 10.6 版本下的 Cocoa 并发问题的指导。我正在将“for”循环转换为使用 NSOperations,但大多数时候,代码只是在循环的某个时刻卡住。我可以在控制台中看到 N
我正在使用 ReportViewer 控件和自定义打印作业工作流程,这给我带来了一些问题。我的代码看起来有点像这样: ids.ForEach(delegate(Guid? guid)
我有以下成功复制文件的代码。但是,它有两个问题: progressBar.setValue() 之后的 System.out.println() 不会打印 0 到 100 之间的间隔(仅打印“0”直到
我是一名优秀的程序员,十分优秀!