Hello
I have a HTTPS web server and a web socket class to handle each connection. I have a simple B4A app that connects to the server and receives 64 bytes every 10 seconds, so the connection to the server is always on. (BTW this is all early development code to figure out how things should be done)
So, yesterday evening I loaded up VisualVM so I could monitor the thread that is connected. This morning when I checked VisualVM this is what I saw:
The above show that over 5500 threads had been created by one connection. I am not sure if this is normal.
Here is the code for the WebSocket Class
It would appear that a new thread(s) is created each time the send occurs. I would appreciate any comments on this.
Regards
John.
I have a HTTPS web server and a web socket class to handle each connection. I have a simple B4A app that connects to the server and receives 64 bytes every 10 seconds, so the connection to the server is always on. (BTW this is all early development code to figure out how things should be done)
So, yesterday evening I loaded up VisualVM so I could monitor the thread that is connected. This morning when I checked VisualVM this is what I saw:
The above show that over 5500 threads had been created by one connection. I am not sure if this is normal.
Here is the code for the WebSocket Class
B4X:
'WebSocket class
Sub Class_Globals
Private ws As WebSocket
Private timer1 As Timer
Private session_id As String
End Sub
Public Sub Initialize
DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss.SSS"
Log(DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & ":" & session_id & ":INFO:websocket.Initialize")
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log(DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & ":" & session_id & ":INFO:websocket.Connected")
ws = WebSocket1
Dim session As HttpSession = ws.UpgradeRequest.GetSession
session_id = session.Id
Log(DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now)& ":" & session_id & ":INFO:websocket.Socket " & ws.Secure)
timer1.Initialize("timer1", 10000)
timer1.Enabled = True
End Sub
Sub Timer1_Tick
Dim s As String
timer1.Enabled = False
Dim APSU As ApacheSU
' // create 1MB
s = APSU.Repeat("W",64) ' 128k
' // send
ws.RunFunction("ServerTime", Array As Object(s))
ws.Flush
Log(DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & ":" & session_id & ":INFO:websocket.Timer1_Tick:SEND")
timer1.Enabled = True
End Sub
Sub Device_Message(Params As Map)
Log("Device message: " & Params.Get("message"))
End Sub
Private Sub WebSocket_Disconnected
timer1.Enabled = False
Log(DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & session_id & ":INFO:websocket.Disconnected")
End Sub
It would appear that a new thread(s) is created each time the send occurs. I would appreciate any comments on this.
Regards
John.