14 Replies Latest reply: Aug 29, 2010 8:44 PM by 843793 RSS

    NEW TO RMI : Including threads in RMI

    843793
      I am having a hierarchical design as below

      1 Server will have 10 Subordinates who are Clients and Each Client will have 5 Slaves (Total 50)

      I am having a Thread array[10] in the server to call the clients to start and the Client class has Thread array[50] calling up 5 slaves per client call.

      I don't want Server to ask clients to start another cycle of work untill one is complete.

      Questions:

      1. How do I use the Wait() and Notify() methods in RMI?
      2. Is RMI doing its jobs parallelly without implementing threads? (As it works on different JVMs)

      Regards,

      Mark.
        • 1. Re: NEW TO RMI : Including threads in RMI
          EJP
          1. How do I use the Wait() and Notify() methods in RMI?
          You can't use them remotely. You would have to write and implement suitable remote interfaces.
          2. Is RMI doing its jobs parallelly without implementing threads? (As it works on different JVMs)
          All JVMs have threads, by definition, and RMI uses threads on all of them.

          This sounds more like a message queueing system than an RMI system to me.
          • 2. Re: NEW TO RMI : Including threads in RMI
            843793
            Hi,

            I sorted it... and I understand that the RMI is inherited with threading mechanism. it is just I use this for one of my experiments in distributed processing, hence that RMI was easy to use.

            ANOTHER PROBLEM.

            I am having a execution cycle of 10000 which means that server will call the clients and clients will call the clients for 10000 times... the problem is that when it is halfway(some what in 4000 cycles or 6000) I use to get eh following errors
            1.
            Client Runnable: 4 Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157 nested exception is: java.net.BindException: Address already in use:
            2.
            Server Runnable Calling Client: [8] Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect

            3.
            Server Runnable Calling Client: [3] Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect
            Server Runnable Calling Client: [6] Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect
            Server Runnable Calling Client: [8] Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect

            4.
            Client Runnable: 5 Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect

            5.
            Server Runnable Calling Client: [9] Error: java.rmi.ConnectIOException: Exception creating connection to: 136.186.6.157; nested exception is: java.net.BindException: Address already in use: connect

            I export my Server and Client Objects on 127.0.0.0:1099 and this thows me an exception for 136.186.6.157 (My Computer IP)
            • 3. Re: NEW TO RMI : Including threads in RMI
              EJP
              You're running out of local ports at the client. Are you using RMIClientSocketFactories by any chance, and if so do they implement equals() correctly?
              • 4. Re: NEW TO RMI : Including threads in RMI
                843793
                I am not familiar with the RMIClientSocketFactories... I am just exporting Server, Client and Slave Objects and use rebind()
                • 5. Re: NEW TO RMI : Including threads in RMI
                  EJP
                  OK then are you doing this from lots of threads simultaneously? Whatever it is, you are running out of outbound ports. You'll have to sequentialize more.
                  • 6. Re: NEW TO RMI : Including threads in RMI
                    843793
                    Correct!

                    I am running them simultaneously using threads... Server calls the 10 Clients in a thread and Each Client calls its Slave in a Thread and... on the way back the Slaves report to Client and each client report to the Server..

                    However... the Server waits for all the clients to respond to him to start the next cycle...

                    So you still think that the method should be synchronized?
                    • 7. Re: NEW TO RMI : Including threads in RMI
                      843793
                      I tried to monitor the the Processors using JConsole and I just checked the summary of the Server process as it is just one jvm and it showed me folowing

                      Live threads:     21
                      Peak:    141
                      Daemon threads:     19
                      Total threads started: 54,264

                      I guess the other processors (10 clients and 10 slaves) also has set of threads started and they also use individual ports for communication? correct?

                      So i have 65k ports to play around
                      • 8. Re: NEW TO RMI : Including threads in RMI
                        EJP
                        I said sequentialized, not synchronized. You can use lots of threads but each one needs a new connection of its own, and when you run out of outbound ports it means you are using too many connections which in turn means you are using too many threads. Try cutting them in half.

                        NB you don't have 64k outbound ports available, you have about 5000 on Windows systems, and that's total for the entire operating system over all cores. There's a Registry tweak to up it but you won't get anywhere near 64k, when you consider the listening ports that are already allocated and the fact that you can't use 1-1023 anyway.
                        • 9. Re: NEW TO RMI : Including threads in RMI
                          843793
                          Thanks it is helping I have removed the threads in the client and it ran for the whole cycle and now I am trying with 2 slaves per client for 50000 cycles... and it seems to be working fine as well.

                          The ideal place for me to use this is on a grid using SSH to multiple hosts then this error would not be a problem at all ya?
                          • 10. Re: NEW TO RMI : Including threads in RMI
                            EJP
                            The ideal place would be whatever configuration won't stress the number of outbound ports per client host.
                            • 11. Re: NEW TO RMI : Including threads in RMI
                              843793
                              check it out this link;
                              http://cs.swan.ac.uk/~csneal/InternetComputing/ThreadCallBack.html
                              • 12. Re: NEW TO RMI : Including threads in RMI
                                843793
                                Thanks.

                                It is helpful for me to control the thread.... but my sole purpose of this program is to demonstrate distributed parallel computations. So my concern is I am testing this in a Dual Core - Windows XP 32bit configuration and If I am going to deploy this in a real environment in a GRID ideally I should not worry about these problems correct?

                                I would be assigning each remote object a dedicated machine in the GRID?

                                Regards

                                Mark.
                                • 13. Re: NEW TO RMI : Including threads in RMI
                                  843793
                                  ejp,

                                  Well, like you said the ideal environment would be where RMI programs meant to run, which is distributed. However, I would like to know if there is a way to do GC or re-initiation of Threads after each cycle as each cycle of test would be independent of each other. May be some sort of GC on remote objects so that after each cycle they would be fresh objects.

                                  Tks
                                  • 14. Re: NEW TO RMI : Including threads in RMI
                                    EJP
                                    I don't know enough about your system to really understand your question, but RMI already does distributed garbage collection, and Java already does local garbage collection.