我正在阅读此类的代码:
public class MultiThreadedServer implements Runnable {
// some more code
protected Thread runningThread = null;
public void run() {
synchronized(this) {
this.runningThread = Thread.currentThread();
}
// lots of code
}
}
Run Code Online (Sandbox Code Playgroud)
这是什么意思?线程本身用作锁定资源的标志?我根本不明白。
有谁知道 ?
我需要计算一个函数的执行时间.
目前,我使用time.h
在功能的开头:
time_t tbegin,tend;
double texec=0.000;
time(&tbegin);
Run Code Online (Sandbox Code Playgroud)
返回前:
time(&tend);
texec = difftime(tend,tbegin);
Run Code Online (Sandbox Code Playgroud)
它工作正常,但作为整数给我一个texec的结果.
如何以毫秒为单位执行时间?
我需要帮助才能知道为什么我的一份准备好的陈述没有被执行.这是代码:
准备好的声明:
updaterBalance = connection.prepareStatement("UPDATE accounts SET balance = ? WHERE account_id = ?")
Run Code Online (Sandbox Code Playgroud)
桌子 :
statmnt.executeUpdate("CREATE TABLE accounts ( account_id INTEGER, balance DOUBLE PRECISION)");
statmnt.executeUpdate("ALTER TABLE accounts ADD CONSTRAINT balance_must_be_positive CHECK (balance >= 0)");
Run Code Online (Sandbox Code Playgroud)
失败的方法:
public boolean transfer(int from, int to, double amount) throws DataStoreException {
try {
lookForAccount.setInt(1, to);
ResultSet result = lookForAccount.executeQuery();
if(result.next()) {
result.close();
lookForAccount.setInt(1, from);
ResultSet result2 = lookForAccount.executeQuery();
if(result2.next()) {
updaterBalance.setDouble(1, result2.getDouble("balance") - amount);
updaterBalance.setInt(2, from);
updaterBalance.executeUpdate();
result2.close();
updaterBalance.setDouble(1, result2.getDouble("balance") + amount);
updaterBalance.setInt(2, to); …Run Code Online (Sandbox Code Playgroud)