開心生活站

位置:首頁 > IT科技 > 

java,execute

IT科技1.42W

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java execute是什麼,讓我們一起了解一下?

execute用於執行返回多個結果集、多個更新計數或二者組合的語句。execute方法僅在語句能返回多個ResultSet對象、多個更新計數或ResultSet對象與更新計數的組合時使用。

在使用execute處理過程出現多個結果的情況怎麼辦?

當執行某個已存儲過程 或動態執行未知 SQL 字符串(即應用程序程序員在編譯時未知)時,有可能出現多個結果的情況。

java execute

例如,假定已知某個過程返回兩個結果集,則在使用方法 execute 執行該過程後,必須調用方法 getResultSet 獲得第一個結果集,然後調用適當的 getXXX 方法獲取其中的值。

要獲得第二個結果集,需要先調用 getMoreResults 方法,然後再調用 getResultSet 方法。如果已知某個過程返回兩個更新計數,則首先調用方法 getUpdateCount,然後調用 getMoreResults,並再次調用 getUpdateCount。

實戰操作:最常調用的execute()方法是怎樣的?

public void execute(Runnable command) {    if (command == null)        throw new NullPointerException();     int c = ctl.get();    if (workerCountOf(c) < corePoolSize) {        if (addWorker(command, true))            return;        c = ctl.get();    }    if (isRunning(c) && workQueue.offer(command)) {        int recheck = ctl.get();        if (! isRunning(recheck) && remove(command))            reject(command);        else if (workerCountOf(recheck) == 0)            addWorker(null, false);    }    else if (!addWorker(command, false))        reject(command);}

execute()內部的調用邏輯非常清晰,如果當前線程池的工作線程數量小於corePoolSize,那麼直接調用addWoker(),來添加工作線程。



標籤:java execute