• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time-sensitive multithreaded application?

 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been having a problem for a couple weeks so I finally figured I would post and see if anyone had any sort of tips or ideas. I'm not even 100% sure this is a Thread related problem, but I think it is.

Anyway, the application is essentially a group (less than 5) of independent servers, each running in their own Threads. There is one client for every server. There are potentially ~10-11 Threads on both the Client and Server, but half of them are waiting on a join.

The bothersome part is the fact that in order for the Threads to stay alive, the client needs to send a keep-alive message (or a real message) within a certain time period (say 1 second). Things seem to work for a random amount of time, but there will eventually be a point where a message is sent a good amount of time after intended. The delay generally comes from random points in the code, be it sending a log message or coming out of a synchronized block.

The way I have things setup now, as soon as I send a message, I populate a variable that tells what time the next message should be sent, wait with a timeout of the difference between next message and current time, then send the message. I generally send messages at a fraction of the designated timeout (say 800ms for a 1000ms timeout)

Things I have tried:
Running Client(s) and Server(s) on different PCs
Running Client(s) and Server(s) on Linux and Windows
Inserting a bunch of Thread.sleep(1) calls in case the other Threads weren't being given a chance to run.

I know that in Java Threads that there are no guarantees, but how do you guys usually implement time sensitive applications like this?

I can't post real code, but I'll give you guys a good idea of the algorithim.

BTW, sorry for the length.


[ June 08, 2005: Message edited by: Martin Mathis ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know your protocol ... does ping() get an ack? If not, the "waitingAck = true" right after ping might be a problem.

Does the logic here just alternate? One time through waitingAck is false, the next time through it is true. Where is the real send messsage ... on another thread? I guess it sets waitingAck true, also.
 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, any message sent expects and ack. Your assumption that it alternates is correct. The ping method essentially just writes the data to a SocketChannel and sets awaitingAck to true. I don't show it, but any 'real' message would do the same.

Didn't want to go and make things too complicated.

I think I've decided to just get a bit more lenient with the timing and see how much that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!