Skip to content

Instantly share code, notes, and snippets.

@fabriziofortino
Created September 18, 2013 10:57
Show Gist options
  • Save fabriziofortino/6607550 to your computer and use it in GitHub Desktop.
Save fabriziofortino/6607550 to your computer and use it in GitHub Desktop.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
public class TestCloseConnection {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(20);
for (int i = 0; i < 30000; i++) {
MyRunnable runnable = new MyRunnable(i);
executor.execute(runnable);
}
// This will make the executor accept no new threads
// and finish all existing threads in the queue
executor.shutdown();
Thread.sleep(60000);
}
static class MyRunnable implements Runnable {
private int id;
public MyRunnable(int id) {
this.id = id;
}
@Override
public void run() {
ODatabaseDocumentTx conn = null;
try {
conn = new ODatabaseDocumentTx("remote:localhost/mydb").open("admin", "admin");
System.out.println("Opened " + id + " connection " + conn);
// do stuff
} finally {
conn.close();
System.out.println("Closed " + id + " connection");
}
}
}
}
@laa
Copy link

laa commented Sep 18, 2013

Yes I got absolutely the same one )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment