Skip to content

Commit

Permalink
add loom jdbc test
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Aug 25, 2023
1 parent 346252c commit 0229229
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sample/src/LoomTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import com.sun.net.httpserver.HttpServer
import klite.Config
import klite.jdbc.PooledDataSource
import klite.jdbc.query
import java.net.InetSocketAddress
import java.util.concurrent.Executors

fun main() {
Config.useEnvFile()
val db = PooledDataSource(maxSize = 100)
HttpServer.create(InetSocketAddress(8080), 10).apply {
executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("req-", 1).factory())
createContext("/hello") { e ->
val dbTime = db.query("select pg_sleep(1), clock_timestamp()") { getString(2) }.first()
e.sendResponseHeaders(200, 0)
e.responseBody.writer().use { it.write("$dbTime, ${Thread.currentThread().name} ${Thread.currentCarrierThread().name}\n") }
}
start()
}
}

0 comments on commit 0229229

Please sign in to comment.