• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 79177
377
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic