📄 pool.c
字号:
#include "ocilib.h"
#define MAX_THREADS 50
#define MAX_CONN 10
#define SIZE_STR 260
void worker(OCI_Thread *thread, void *data)
{
OCI_Connection *cn = OCI_ConnPoolGetConnection(data);
char str[SIZE_STR];
/* application work here */
str[0] = 0;
OCI_Immediate(cn, "select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual", OCI_ARG_TEXT, str);
printf("%s\n", str);
/* ... */
OCI_ConnectionFree(cn);
}
int main()
{
OCI_Thread *th[MAX_THREADS];
OCI_ConnPool *pool;
int i;
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED))
return EXIT_FAILURE;
/* create pool */
pool = OCI_ConnPoolCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT, 0, MAX_CONN, 1);
/* create threads */
for (i = 0; i < MAX_THREADS; i++)
{
th[i] = OCI_ThreadCreate();
OCI_ThreadRun(th[i], worker, pool);
}
/* wait for threads and cleanup */
for (i = 0; i < MAX_THREADS; i++)
{
OCI_ThreadJoin(th[i]);
OCI_ThreadFree(th[i]);
}
OCI_ConnPoolFree(pool);
OCI_Cleanup();
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -