B4J Question <Solved> ConnectionPool (maxpoolsize Issue)

Harris

Expert
Licensed User
Longtime User
ABMaterial related.... (for me)

Connectionpool size is really not the issue...


Buried in the posts, I managed to solve a ConnectionPool issue.... (took another 2 days to discover - my bad)

Issue:
Updating any record, it was successful until it hit the (pool) maxpoolsize setting (which is hard coded - unless you change it)- explained later...).

Note: Not a problem with the lib - however how it was being called.

Proper way to call (example):
B4X:
 Log(" Trying to get connection")
        
           ' CREATE a SQL object (sq)
           Dim sq as SQL
           sq = DB.pool.GetConnection
           Log(" AFTER Trying to get connection")
                   
           Dm m As Map = DBUtils.ExecuteMap(sq , "SELECT * FROM cv_contactos WHERE id_contacto = ?", Array As String(contactId))
             If m.IsInitialized = True Then
                     Log(" building sheet - M is inited")
                     txEmpresa.Text = "" & m.Get("organizacion")
                      txNombre.Text = "" & m.Get("nombres")
                      txTelefono.Text = "" & m.Get("telefono")
                      txEmail.Text = "" & m.Get("email")
                       txComentario.Text = "" & m.Get("comentario")
                       Try
                             page.ShowModalSheet("myModal")
                       Catch
                             Log(" can't show sheet: "&LastException.Message)
                        End Try
               End If
               'RELEASE (free) this object after use...
              sq.Close


WRONG WAY:

B4X:
      DBUtils.DeleteRecord(DB.pool.GetConnection, "cv_contactos", Where)
                Toast("Record Deleted: " & contactId & "!", 5000)

                Dim tbContacts As ABMTable = page.Component("tblContacts")
                tbContacts.Clear
                FillcontactosTable(tbContacts, DB.pool.GetConnection.ExecQuery("SELECT id_contacto, pais, organizacion, nombres, DATE_FORMAT(fecha,'%d-%m-%Y') FROM cv_contactos ORDER BY id_contacto DESC LIMIT 200"))
                tbContacts.Refresh


The problem here is "DBUtils.DeleteRecord(DB.pool.GetConnection"

The pool is called inline "without" being assigned to a var that can be released later... (as in first example)

Apparently, there is no object created (addressable) to release from pool later..
So, when you run out of pool space, the app will AV (or stop...).


So, DO NOT inline create the pool connection.... It will eventually fail and hang the app.
Dim it first: (newobj as SQL)
add it to the pool: newobj= DB.pool.GetConnection
{do your stuff}
release it back (free object) when done: (newobj.Close)

I originally thought this was a AMMaterial issue (since I am learning it), but it has nothing to do with it...

To change maxpoolsize

B4X:
Public Sub init
    Dim JdbcUrl As String = Main.settings.Get("JdbcUrl")
    Dim driverClass As String = Main.settings.Get("DriverClass")
    Dim dbuser As String = Main.settings.Get("DBUser")
    Dim dbpassword As String = Main.settings.Get("DBPassword")
    Try
       pool.Initialize(driverClass, JdbcUrl, dbuser, dbpassword)
    Catch
       Log("Last Pool Init Except: "&LastException.Message)
    End Try

   ' change pool size...
    Dim jo As JavaObject = pool
    jo.RunMethod("setMaxPoolSize", Array(100))
End Sub



I have tried it with a pool size of "10" and it works fine... no hangs or crashes.

Thanks
 
Last edited:

dar2o3

Active Member
Licensed User
Longtime User
Thank you very much, I had the same error and could fix my problem thanks to your explanation.
 
Upvote 0
Top