vrogier / ocilib

OCILIB (C and C++ Drivers for Oracle) - Open source C and C++ library for accessing Oracle databases
http://www.ocilib.net
Apache License 2.0
325 stars 119 forks source link

Regarding using ocilib::Pool to get links ,what happens if the maximum link is reached? #340

Closed MagicXran closed 1 year ago

MagicXran commented 1 year ago

Regarding using ocilib::Pool to get links, what happens if the maximum link is reached? This is a code snippet I wrote, and I'm not sure if I need to do it. Or what should I do? Please advise.

class xxx
{
public:

    inline ocilib::Connection  getConnection()
    {
        std::unique_lock lock(m_mtx);

        while (pool_.GetBusyConnectionsCount() >= pool_.GetMaxSize())
        {
            std::cerr << "connections resoures is poor ~ please waiting for ..." << std::endl;
            m_cond.wait(lock, [this] {return pool_.GetBusyConnectionsCount() < pool_.GetMaxSize(); });
        }
        auto conn = std::move(pool_.GetConnection());
        lock.unlock();
        return conn;
    }

///...
private:
ocilib::Pool pool_;
}
vrogier commented 1 year ago

When oracle pool is full, requesting connection is a blocking call until the pool has an available one. You can change that behaviour to no block using Pool::SetNoWait(false)

Vincent