This is a sample multithreaded java code (not scala) which fails with "No 
more resources available in pool" if you do not use db.close()

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;

public class ThreadExample {

    private static final OSQLSynchQuery query = new OSQLSynchQuery("SELECT 
FROM V");
    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            new Thread("" + i) {
                public void run() {

                    // ODatabaseDocumentTx db = new 
ODatabaseDocumentTx("remote:localhost/GratefulDeadConcerts").open("admin", 
"admin");
                    // or use pool
                    ODatabaseDocumentTx db = 
ODatabaseDocumentPool.global(1,40).acquire("remote:localhost/GratefulDeadConcerts",
 
"admin", "admin");

                    System.out.println(" 1 -- Thread: " + getName() + " 
running");
                    db.query(query);
                    // db.close();    // if you do not close it will fail 
with : No more resources available in pool (max=40)

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
}


com.orientechnologies.common.concur.lock.OLockException: No more resources 
available in pool (max=40). Requested resource: 
remote:localhost/GratefulDeadConcerts
    at 
com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:70)
    at 
com.orientechnologies.common.concur.resource.OReentrantResourcePool.getResource(OReentrantResourcePool.java:84)
    at 
com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:158)
    at 
com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:138)
    at 
com.orientechnologies.orient.core.db.ODatabasePoolBase.acquire(ODatabasePoolBase.java:128)
    at ThreadExample$1.run(ThreadExample.java:22)


Il giorno mercoledì 4 gennaio 2017 15:19:46 UTC+1, leon...@adimplere.com.br 
ha scritto:
>
> Hi,
>
> May anyone use the orientdb with java so that it closes the used connections 
> and avoids the error "Reached maximum number of concurrent connections" ?
>
> A simple test that I do. I'm using java8 and orientdb 2.2.14 with remote. 
> Config sets don't work.
>
>    val poolFactory = new OPartitionedDatabasePoolFactory()
>     poolFactory.setMaxPoolSize(40)
>
>     val pool = poolFactory.get("remote:db.adimplere.com.br/adimplere", 
> "admin", "ab12HTT")
>     val conn = pool.acquire()
>
>     try {
>      
>       val query = StringBuilder.newBuilder
>
>       query.append("SELECT @this.tojson(\"fetchPlan:*:-1\") AS itens FROM 
> Parceiro limit 1000;")
>
>       //connection.query(new OSQLSynchQuery[ODocument]("SELECT * FROM Cliente 
> WHERE cpfCnpj=?").setFetchPlan("*:-1"))
>
>       val res = conn.query[java.util.List[ODocument]](new 
> OSQLSynchQuery[ODocument](query.toString)).asScala.toList
>
>       val result = {
>         if (res.isEmpty) {
>           None
>         } else {
>           Some(res(0).field("itens"))
>         }
>       }
>
>       result
>
>     } finally {
>       conn.close()
>       pool.close()
>       poolFactory.close()
>     }
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to orient-database+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to