File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Array of connection objects in multithreaded environment, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Array of connection objects in multithreaded environment," Watch "Array of connection objects in multithreaded environment," New topic
Author

Array of connection objects in multithreaded environment,

Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
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.






Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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 ... ...


BEE MBA PMP SCJP-6
aryan Sharma
Greenhorn

Joined: Oct 10, 2005
Posts: 27
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 .....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array of connection objects in multithreaded environment,