Hello,
I am having a problem with jserver and connection pool. After some time server is not responding and logs show timeout errors. I am closing the pool connection after the work done and close the resultset also. here is the code:
main:
and the coinlist module for example ( because all other modules are same)
I am having a problem with jserver and connection pool. After some time server is not responding and logs show timeout errors. I am closing the pool connection after the work done and close the resultset also. here is the code:
main:
B4X:
'Non-UI application (console application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: true
#AdditionalJar: mysql-connector-java-5.1.43-bin.jar
#End Region
Sub Process_Globals
Private srvr As Server
Public pool As ConnectionPool
End Sub
Sub AppStart (Args() As String)
srvr.Initialize("srvr")
srvr.Port = 8080
srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")
srvr.AddHandler("/v1/coinlist", "coinlist", False)
srvr.AddHandler("/v1/pairlist", "pairlist", False)
srvr.AddHandler("/v1/coinlive", "coinlive", False)
pool.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/kripto?useSSL=false", _
"root", "xxx")
Log("Testing the database connection")
srvr.Start
Log("Server started")
StartMessageLoop
End Sub
and the coinlist module for example ( because all other modules are same)
B4X:
'Class module
Sub Class_Globals
Private mreq As ServletRequest 'ignore
Private mresp As ServletResponse 'ignore
End Sub
Public Sub Initialize
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
mreq = req
mresp = resp
Dim connection As SQL = Main.Pool.GetConnection
Try
Dim cursor As ResultSet
Dim n As Map
Dim l As List
l.Initialize
n.Initialize
cursor=Main.pool.GetConnection.ExecQuery("SELECT sembol,name,table_name from genel")
Do While cursor.NextRow
' n = CreateMap("symbol" :cursor.GetString("sembol"),"value" :cursor.GetString("last"),"changebynumber": cursor.GetString("changenumber"),"changebypercent": cursor.GetString("changepercent"),"updated": cursor.GetString("updated"))
n= CreateMap("symbol" :cursor.GetString("sembol"),"name":cursor.GetString("name"),"source":cursor.GetString("table_name"))
l.Add(n)
Loop
Dim jsong As JSONGenerator
jsong.Initialize2(l)
'Log(jsong.ToString)
Catch
Log(LastException)
End Try
connection.Close 'return to pool
cursor.Close
resp.ContentType = "application/json"
resp.Write(jsong.ToString)
End Sub