Guest User

Untitled

a guest
Sep 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class TestThread
  2. {
  3. static public function main()
  4. {
  5. for (i in 0...40) //Create a few threads
  6. {
  7. trace("Start thread "+i);
  8. var th = neko.vm.Thread.create(callback(doQuery, i));
  9. Sys.sleep(0.5);
  10. }
  11.  
  12. while (true)
  13. {
  14. //Waiting for threads
  15. Sys.sleep(10);
  16. }
  17. }
  18.  
  19. static private function doQuery(id:Int)
  20. {
  21. var cnx = sys.db.Mysql.connect(
  22. {
  23. host : "localhost",
  24. port : 3306,
  25. database : "testdb",
  26. user : "root",
  27. pass : "",
  28. socket : null
  29. }); //Open a new database connection
  30.  
  31. sys.db.Manager.cnx = cnx; //Try to use it...
  32.  
  33. try
  34. {
  35. while (true)
  36. {
  37. sys.db.Manager.cleanup(); //Clean cache so it really uses database
  38. var a = TestTable.manager.all();
  39. Sys.sleep(0.2);
  40. }
  41. }
  42. catch (e:Dynamic)
  43. {
  44. trace("Thread "+id+" crashed ! "+e);
  45. }
  46. }
  47. }
  48.  
  49. @:id(id)
  50. class TestTable extends sys.db.Object
  51. {
  52. public var id:Int;
  53. public var text:String;
  54.  
  55. static public var manager = new sys.db.Manager<TestTable>(TestTable);
  56. }
Add Comment
Please, Sign In to add comment