Created
September 18, 2013 10:57
-
-
Save fabriziofortino/6607550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes I got absolutely the same one )