B4J Question Server pages working in Debug but not Release [Solved]

lip

Active Member
Licensed User
Longtime User
This page works in Debug but hangs in Release

Handler:
'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
    Resp.ContentType = "text/html"
    
    Log("Debug: Setup Called-1")
    Dim TestC As ResultSet = Main.EnergyDB.ExecQuery("SELECT DeviceSN FROM Device")
    Log("Debug: Setup Called-2")
    If TestC.NextRow Then
        Log("Debug: DeviceSN = " & TestC.GetInt("DeviceSN"))
        Resp.Write("Debug: DeviceSN = " & TestC.GetInt("DeviceSN"))
    End If
    TestC.Close
    Log("Debug: Setup Called-3")

Logs in Debug:

Debug: Setup Called-1
Debug: Setup Called-2
Debug: DeviceSN = 1202
Debug: Setup Called-3

Logs in Release:

Debug: Setup Called-1
 

alwaysbusy

Expert
Licensed User
Longtime User
I think there is a difference that in Debug the app runs in a single thread and in release multi threaded.

Normally I get a connection from the pool, run the queries, and then release it immediately when not needed anymore so it frees up for others.

Something like this:
B4X:
Sub Handle(req As ServletRequest, Resp As ServletResponse)
...
    Dim connection As SQL = DBModule.Pool.GetConnection
    Try
         'work with connection
    Catch

    End Try
    connection.Close 'return to pool
...
End Sub
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
No idea why the problem started, but the resolution was to add a SQL Object into the Process Globals of each Handler.

Until now I had one SQL object in Process Globals of Main, which I initialised in AppStart() then called from every module. There are about 150 references to the SQLite object in Main class ie EnergyDB.ExceQuery() and 200 queries and non-queries in the other code modules and Handlers ie Main.EnergyDB.ExecQuery(). This has worked fine for many years until last week.

I have now added a SQL Object into each handler which I initialise in Sub Handle(req As ServletRequest, resp As ServletResponse) and then use SQL.Close at the end of the Handler Sub.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I have now added a SQL Object into each handler which I initialise in Sub Handle(req As ServletRequest, resp As ServletResponse) and then use SQL.Close at the end of the Handler Sub.

Note that you only must initialize the pool once. And in each handler then a GetConnection to this pool and a Close at the end.
 
Upvote 0
Top