小编Csi*_*Csi的帖子

在带有 var=Thread.currentThread() 的代码块上同步(...)

我正在阅读此类的代码:

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)

这是什么意思?线程本身用作锁定资源的标志?我根本不明白。

有谁知道 ?

java multithreading runnable

5
推荐指数
1
解决办法
345
查看次数

计算执行函数的时间

我需要计算一个函数的执行时间.

目前,我使用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的结果.

如何以毫秒为单位执行时间?

c++ time time.h

2
推荐指数
1
解决办法
7339
查看次数

测试两个result.next()

我需要帮助才能知道为什么我的一份准备好的陈述没有被执行.这是代码:

准备好的声明:

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)

java database oracle jdbc resultset

-1
推荐指数
1
解决办法
80
查看次数

标签 统计

java ×2

c++ ×1

database ×1

jdbc ×1

multithreading ×1

oracle ×1

resultset ×1

runnable ×1

time ×1

time.h ×1