• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems with threads and spawning.

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello people...
I am doing an RMI project and I have run into a small problem. Hope someone can help me out. I have 3 RMI servers which all need to communicate via some back end channel (to do some time syncing work). I decided to use sockets for this since I have to send small amounts of data. The problem is that when I create the server socket in the constructor of one of my actual servers, it blocks the thread on creation. And the second instance of the actual server is not created at all. I will highlight it in the code below.

Is there SOME WAY that I can create a new thread and hand off just the socket part of the code below to the new one so that it can create and block without affecting the main thread executing?

public FrontEnd(String serverIP, int serverPort, String serverName, int processId, int portNum)
throws RemoteException
{
int FEserverPort = serverPort;
String FEserverIp = serverIP;

this.processID = processId;
this.socketPort = portNum;

try
{
FEReg = LocateRegistry.createRegistry(FEserverPort);
FEReg.rebind(serverName, this);

System.out.println ("Starting Server Instance on port " + FEserverPort);
System.out.println ("Server bound to name " + serverName);

BEReg = LocateRegistry.getRegistry(serverIp, backEndServerPort);
BEServer = (MessageInterface)(BEReg.lookup("tweetRMI"));

}
catch(Exception e)
{
System.out.println ("The Registry is causing an error");
e.printStackTrace();
}

try
{
this.serverSocket = new ServerSocket(socketPort);
this.incomingConn = serverSocket.accept ();
===================> Server socket creation and blocks here!!!
}
catch (Exception e)
{
System.out.println ("The Socket is causing an error");
e.printStackTrace();
}

objEATS = new ElectionAndTimeSync(processID, socketPort, incomingConn);
}

public static void main(String[] args)
{
// TODO Auto-generated method stub
try
{
FrontEnd serverObject1 = new FrontEnd("localhost", 9002, "feRMI", 2, 10002); =============> This calls the constructor and the thread blocks when the socket is created.
FrontEnd serverObject2 = new FrontEnd("localhost", 9011, "fe1RMI", 3, 10003); =============> This is never called since the thread has blocked due to the above call.
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult for "beginning". Moving thread.
 
Arthur, where are your pants? Check under this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic