Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TestThread
- {
- static public function main()
- {
- for (i in 0...40) //Create a few threads
- {
- trace("Start thread "+i);
- var th = neko.vm.Thread.create(callback(doQuery, i));
- Sys.sleep(0.5);
- }
- while (true)
- {
- //Waiting for threads
- Sys.sleep(10);
- }
- }
- static private function doQuery(id:Int)
- {
- var cnx = sys.db.Mysql.connect(
- {
- host : "localhost",
- port : 3306,
- database : "testdb",
- user : "root",
- pass : "",
- socket : null
- }); //Open a new database connection
- sys.db.Manager.cnx = cnx; //Try to use it...
- try
- {
- while (true)
- {
- sys.db.Manager.cleanup(); //Clean cache so it really uses database
- var a = TestTable.manager.all();
- Sys.sleep(0.2);
- }
- }
- catch (e:Dynamic)
- {
- trace("Thread "+id+" crashed ! "+e);
- }
- }
- }
- @:id(id)
- class TestTable extends sys.db.Object
- {
- public var id:Int;
- public var text:String;
- static public var manager = new sys.db.Manager<TestTable>(TestTable);
- }
Add Comment
Please, Sign In to add comment