Skip to content

Instantly share code, notes, and snippets.

@zaneli
Last active March 9, 2017 04:32
Show Gist options
  • Save zaneli/20851f29359cc397ef8797684a5c9372 to your computer and use it in GitHub Desktop.
Save zaneli/20851f29359cc397ef8797684a5c9372 to your computer and use it in GitHub Desktop.
call `scalikejdbc.config.DBs.setup(dbName)` multiple times in another threads.
db {
test {
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.99.100/test?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"
user="root"
password="root"
poolInitialSize=10
poolMaxSize=10
poolValidationQuery="select 1 as one"
}
}
package com.zaneli
import scalikejdbc._
import scalikejdbc.config.DBs
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
object Main extends App {
val dbName = 'test
val fs = (1 to 50).map { _ =>
Future {
DBs.setup(dbName) // !?
NamedDB(dbName).readOnly { implicit s =>
val ids = sql"select id from test".map(rs => rs.int("id")).list().apply()
Thread.sleep(5 * 1000)
ids
}
}
}
println(Await.result(Future.sequence(fs), Duration.Inf))
}
MariaDB [test]> show processlist;
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
| 331 | root | 192.168.99.1:50302 | test | Query | 0 | init | show processlist | 0.000 |
| 686 | root | 192.168.99.1:51092 | test | Sleep | 1 | | NULL | 0.000 |
| 687 | root | 192.168.99.1:51093 | test | Sleep | 1 | | NULL | 0.000 |
| 688 | root | 192.168.99.1:51094 | test | Sleep | 1 | | NULL | 0.000 |
| 689 | root | 192.168.99.1:51095 | test | Sleep | 1 | | NULL | 0.000 |
| 690 | root | 192.168.99.1:51096 | test | Sleep | 1 | | NULL | 0.000 |
| 691 | root | 192.168.99.1:51097 | test | Sleep | 1 | | NULL | 0.000 |
| 692 | root | 192.168.99.1:51098 | test | Sleep | 1 | | NULL | 0.000 |
| 693 | root | 192.168.99.1:51099 | test | Sleep | 1 | | NULL | 0.000 |
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
9 rows in set (0.00 sec)
MariaDB [test]> show processlist;
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
| 331 | root | 192.168.99.1:50302 | test | Query | 0 | init | show processlist | 0.000 |
| 736 | root | 192.168.99.1:51173 | test | Sleep | 33 | | NULL | 0.000 |
| 737 | root | 192.168.99.1:51176 | test | Sleep | 33 | | NULL | 0.000 |
| 738 | root | 192.168.99.1:51175 | test | Sleep | 33 | | NULL | 0.000 |
| 739 | root | 192.168.99.1:51177 | test | Sleep | 33 | | NULL | 0.000 |
| 740 | root | 192.168.99.1:51174 | test | Sleep | 33 | | NULL | 0.000 |
| 741 | root | 192.168.99.1:51178 | test | Sleep | 33 | | NULL | 0.000 |
| 742 | root | 192.168.99.1:51179 | test | Sleep | 33 | | NULL | 0.000 |
| 743 | root | 192.168.99.1:51180 | test | Sleep | 33 | | NULL | 0.000 |
| 744 | root | 192.168.99.1:51181 | test | Sleep | 28 | | NULL | 0.000 |
| 745 | root | 192.168.99.1:51182 | test | Sleep | 28 | | NULL | 0.000 |
| 746 | root | 192.168.99.1:51183 | test | Sleep | 28 | | NULL | 0.000 |
| 747 | root | 192.168.99.1:51184 | test | Sleep | 28 | | NULL | 0.000 |
| 748 | root | 192.168.99.1:51185 | test | Sleep | 28 | | NULL | 0.000 |
| 749 | root | 192.168.99.1:51187 | test | Sleep | 28 | | NULL | 0.000 |
| 750 | root | 192.168.99.1:51186 | test | Sleep | 28 | | NULL | 0.000 |
| 751 | root | 192.168.99.1:51188 | test | Sleep | 28 | | NULL | 0.000 |
| 752 | root | 192.168.99.1:51189 | test | Sleep | 22 | | NULL | 0.000 |
| 753 | root | 192.168.99.1:51190 | test | Sleep | 22 | | NULL | 0.000 |
| 754 | root | 192.168.99.1:51191 | test | Sleep | 22 | | NULL | 0.000 |
| 755 | root | 192.168.99.1:51192 | test | Sleep | 22 | | NULL | 0.000 |
| 756 | root | 192.168.99.1:51193 | test | Sleep | 22 | | NULL | 0.000 |
| 757 | root | 192.168.99.1:51194 | test | Sleep | 22 | | NULL | 0.000 |
| 758 | root | 192.168.99.1:51196 | test | Sleep | 22 | | NULL | 0.000 |
| 759 | root | 192.168.99.1:51195 | test | Sleep | 22 | | NULL | 0.000 |
| 760 | root | 192.168.99.1:51197 | test | Sleep | 16 | | NULL | 0.000 |
| 761 | root | 192.168.99.1:51199 | test | Sleep | 16 | | NULL | 0.000 |
| 762 | root | 192.168.99.1:51198 | test | Sleep | 16 | | NULL | 0.000 |
| 763 | root | 192.168.99.1:51201 | test | Sleep | 16 | | NULL | 0.000 |
| 764 | root | 192.168.99.1:51202 | test | Sleep | 16 | | NULL | 0.000 |
| 765 | root | 192.168.99.1:51203 | test | Sleep | 16 | | NULL | 0.000 |
| 766 | root | 192.168.99.1:51200 | test | Sleep | 16 | | NULL | 0.000 |
| 767 | root | 192.168.99.1:51204 | test | Sleep | 16 | | NULL | 0.000 |
| 768 | root | 192.168.99.1:51205 | test | Sleep | 10 | | NULL | 0.000 |
| 769 | root | 192.168.99.1:51206 | test | Sleep | 10 | | NULL | 0.000 |
| 770 | root | 192.168.99.1:51207 | test | Sleep | 10 | | NULL | 0.000 |
| 771 | root | 192.168.99.1:51209 | test | Sleep | 10 | | NULL | 0.000 |
| 772 | root | 192.168.99.1:51208 | test | Sleep | 10 | | NULL | 0.000 |
| 773 | root | 192.168.99.1:51211 | test | Sleep | 10 | | NULL | 0.000 |
| 774 | root | 192.168.99.1:51210 | test | Sleep | 10 | | NULL | 0.000 |
| 775 | root | 192.168.99.1:51212 | test | Sleep | 10 | | NULL | 0.000 |
| 776 | root | 192.168.99.1:51215 | test | Sleep | 4 | | NULL | 0.000 |
| 777 | root | 192.168.99.1:51216 | test | Sleep | 4 | | NULL | 0.000 |
| 778 | root | 192.168.99.1:51217 | test | Sleep | 4 | | NULL | 0.000 |
| 779 | root | 192.168.99.1:51218 | test | Sleep | 4 | | NULL | 0.000 |
| 780 | root | 192.168.99.1:51220 | test | Sleep | 4 | | NULL | 0.000 |
| 781 | root | 192.168.99.1:51219 | test | Sleep | 4 | | NULL | 0.000 |
| 782 | root | 192.168.99.1:51221 | test | Sleep | 4 | | NULL | 0.000 |
| 783 | root | 192.168.99.1:51222 | test | Sleep | 4 | | NULL | 0.000 |
+-----+------+--------------------+------+---------+------+-------+------------------+----------+
49 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment