Hello (Using the JAVA SE Client 4.3.8)
I have a use case where I am connecting to a primary source and, upon connection errors, disconnect the client and switch to a backup connection. However, I ran into the problem since the ClientListeners are single threaded. If I switch to an alternate connection directly from the ClientListener like so...
onStatusChange(String status)
case DISCONNECTED:
clientHandler.switchToAlternateConnection()
Then I reconfigure the connection details of my client, remove the old listener, add a new ClientListener and then attempt to start the new connection, waiting to continue with setup until my client listener receives a status update "CONNECTED:WS-STREAMING". However, due to the single threaded nature of the listeners, my waiting thread is identical to the thread which would theoretically receive the updated status, hence it times out.
My solution was utilizing a new thread for my connection switching, i.e.
onStatusChange(String status)
case DISCONNECTED:
new Thread(clientHandler::switchToAlternateConnection) .start()
however I am wary about spawning new threads. Is this expected behaviour I am seeing and handling or am I doing something wrong? Any help would be appreciated.
Bookmarks