Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of connection objects in multithreaded environment,

 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am working on a the following problem and need your suggestions and ideas

I am reading 10 values from a config file and preparing 10 connections and storing it in an array as of now. All this objects in array are runnable objects.
These 10 objects connect to 10 different server(located in different locations/country) respectively.

I am writing a code to iterate this array get the objects out of it and connect to their respective server.

I have the following scenarios.

1) If Initially the servers are down I need to keep trying to connect to that server with incremental delay ( 1 min ,next try at 2, next try 4... and so on).

2) if any server disconnects I need to keep trying to connect it with a incremental delay.

I used blocking queues and could address the 2nd issue. Whenever object disconnects i pushed the object back in the queue.

The problem I am facing is that if I keep trying for the first connection objects then the other connections in the array/queue would be waiting for their turn.

I need some kind of monitoring mechanism/thread that could address both the situations in a multithreaded environment.

Please advise.





 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about launching each connection in its own thread with one common
object for all of them to report current status, and to forward follow-on
commands. Then each thread can manage its own waits and reconnects.
It sounds like you've already tried part of this.

Jim ... ...
 
aryan Sharma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nilesh Raje wrote:Hi Guys,



The problem I am facing is that if I keep trying for the first connection objects then the other connections in the array/queue would be waiting for their turn.

I need some kind of monitoring mechanism/thread that could address both the situations in a multithreaded environment.

Please advise.



i did not get it. why would it keep trying for first connection object. once its done trying for first connection object and its un-successful in getting connection it would be added at the end of the queue, so obviously the second connection would be tried and not the first connection. first connection would no come into picture only after all the other nine connections have been tried. also consider using priority queue and use retry count for priority .....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic