-
July 26th, 2023, 09:00 PM
#1
Connecting to backup source multithreading
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.
Similar Threads
-
By shabbirh in forum Client SDKs
Replies: 2
Last Post: September 28th, 2012, 10:00 AM
-
By achittoda in forum Adapter SDKs
Replies: 1
Last Post: December 21st, 2009, 10:05 AM
-
By Dr.Dran in forum Adapter SDKs
Replies: 0
Last Post: April 27th, 2009, 02:53 PM
-
By sarbao in forum General
Replies: 1
Last Post: April 16th, 2009, 08:59 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
All times are GMT +1. The time now is 03:50 PM.
Bookmarks