I am taking a distributed course. Now, I want to set a timeout for client when it sends or receiving data from a crushed server, and let it reconnect with a available server. I wanna add something here to let client realized the time has already been long enough.
sendMessage(new TextMessage(kvjson));
TextMessage resultMsg = receiveMessage();
I thought about using a thread here like a counter, and when the time is out, just skip the up statement. but I realized if there is a crushed server, client may just stuck inside the method and never get a return back. plus I don't know how let main process know that my timeout head has already finished. I think it relates something with interrupt and sleep? After checking online source I am still confused. So I post it here. Thank you for ur answer and patient in advance!