Running 2 separate programs at once w/ RMI

Hello Java forum. I am coding a stock market simulator with Java. I need the stock prices to be CONSTANTLY dynamic. So what I have is a driverClass that is the front for the market sim. It displays the stock prices and such, and therefor must grab variables from the engineClass which is constantly looping to randomly increase or decrease the stock values of 50 different stocks. Here is a VERY watered down version of these 2 classes:
driverClass (the front of the program)
public class driverClass
     public static void main (String[]args)
     int stockPrice = 0, numShares = 0, totalPrice = 0;
     /*Some way to take values from the constantly running engineClass
     stockPrice = code to get value from the Dell method in the engineClass
     numShares = Keyboard.readInt();
     totalPrice = numShares * stockPrice
     System.out.print ("The stock's price is " + stockPrice);
     System.out.print (". You have " + numShares + " shares of Dell stock.");
     System.out.println (" Your net worth is " + totalPrice + ".");
}The engineClass (constantly changes all of the stock prices)
public class engineClass
     public static void main (String[]args)
          //Does this have to be a main method (like a driver) or can it/does it have to be in the form of an object class?
          int repeat = 100, stockValue = 20;
          while(repeat > 0)
               Dell(stockValue);
               repeat--;
     public static int Dell (int stockPrice)
          return stockPrice;
     //does basically this for the other 49 stocks
}So what I need is to be able to call on a method in the engineClass FROM the driverClass while the engine is constantly changing all of the stock prices. Everyone has told me that RMI is the BEST way to do this, but RMI is extremely confusing to me. All the talk of servers and clients, while not retaining the same network meaning perhaps, still throws me off. Can someone please tell me the simplest way to use RMI to access a method in the engineClass from the driverClass with both of them running. Thanks!

One FINAL issue to clear up it seems:
Okay everything is going well, except it seems I have one final issue at hand. The method that I am remotely invoking is static, and I can't think of a way to make it so that it doesn't have to be. Look at my code:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
Client:
public class Drive
    public static void main(String[] args)
          String host = (args.length < 1) ? null : args[0];
          try
              Registry registry = LocateRegistry.getRegistry(host);
              RemoteInterface stub = (RemoteInterface) registry.lookup("Hello");
              int response = stub.UnionPacific();
              System.out.println("response: " + response);
          catch (Exception e)
              System.err.println("Client exception: " + e.toString());
              e.printStackTrace();
    private Drive()
}Server:
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Engine implements RemoteInterface
     public static int price, total1, total2, current = 1;
     public static boolean cont = true;
    public static void main(String[]args)
          try
               java.rmi.registry.LocateRegistry.createRegistry(1099);
               System.out.println("RMI registry ready.");
          catch (Exception e)
               System.out.println("Exception starting RMI registry:");
               e.printStackTrace();
          try
               Engine obj = new Engine();
              RemoteInterface stub = (RemoteInterface) UnicastRemoteObject.exportObject(obj, 0);
              // Bind the remote object's stub in the registry
              Registry registry = LocateRegistry.getRegistry();
              registry.bind("Hello", stub);
              System.err.println("Stock Market Ready");
          catch (Exception e)
              System.err.println("Server exception: " + e.toString());
              e.printStackTrace();
         while(cont)
               price++;
               if(current == 1)
                    //UnionPacific();
                    current = 2;
               else
                    //Altera();
                    current = 1;
     public Engine()
     public int UnionPacific()
          return total1;
     public int Altera()
          return total2;
}Remote Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteInterface extends Remote
    int UnionPacific() throws RemoteException;
    int Altera() throws RemoteException;
}So you see how this works? The main method of the server is constantly updating the totals of both Altera() and UnionPacific(). These 2 need to be invoked remotely, but in order to call them from the static main loop, they also have to be static, but the remote interface does not allow this! It is very annoying. can anyone tell me how to get around this, or a way to make it so my altera and unionpacific methods dont have to be static? THANKS!!!
Edited by: NasaGuru on Mar 11, 2009 6:48 PM

Similar Messages

  • Running 2 separate programs at once w/ interprocess communication

    Hello Java forum. I am coding a stock market simulator with Java. I need the stock prices to be CONSTANTLY dynamic and therefor running in a separate JVM (java virtual machine/ runtime environment). So what I have is a driverClass that is the front for the market sim. It displays the stock prices and such, and therefor must grab variables from the engineClass which is constantly looping to randomly increase or decrease the stock values of 50 different stocks. Here is a VERY watered down version of these 2 classes:
    driverClass (the front of the program)
    public class driverClass
         public static void main (String[]args)
         int stockPrice = 0, numShares = 0, totalPrice = 0;
         /*Some way to take values from the constantly running engineClass
         stockPrice = code to get value from the Dell method in the engineClass
         numShares = Keyboard.readInt();
         totalPrice = numShares * stockPrice
         System.out.print ("The stock's price is " + stockPrice);
         System.out.print (". You have " + numShares + " shares of Dell stock.");
         System.out.println (" Your net worth is " + totalPrice + ".");
    }The engineClass (constantly changes all of the stock prices)
    {codepublic class engineClass
         public static void main (String[]args)
              //Does this have to be a main method (like a driver) or can it/does it have to be in the form of an object class?
              int repeat = 100, stockValue = 20;
              while(repeat > 0)
                   Dell(stockValue);
                   repeat--;
         public static int Dell (int stockPrice)
              return stockPrice;
         //does basically this for the other 49 stocks
    }}So what I need is to be able to call on a method in the engineClass FROM the driverClass while the engine is constantly changing all of the stock prices. I have heard of using COBRA, RMI, sockets and multithreading to achieve this. I want the most BASIC and EASY way to do this. Thank you very much for any help at all. I know it is rude to ask, but I am in a hurry to finish this code and it would be great if someone could give me help here ASAP. Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    jschell wrote:
    Brynjar wrote:
    I've found that Spring simplifies using RMI a lot. Here's an example that looks decent (haven't looked very closely at it):
    [http://www.roseindia.net/spring/springpart4.shtml|http://www.roseindia.net/spring/springpart4.shtml]
    I could be mistaken but I believe that is the site that multiple posters have denigrated as being idiotic.
    And others have also been banned from this site for posting it (presumably because the posts there are so poor.)Hmm, though I said I didn't look very closely I probably should have - you're right, many things there don't look too good. Here's a much better example:
    [http://static.springframework.org/spring/docs/2.0.x/reference/remoting.html|http://static.springframework.org/spring/docs/2.0.x/reference/remoting.html]
    And I seriously doubt that using spring with RMI is going to help the OP.At least speaking from my own experience, I found using Spring for this to be much easier than doing the stub/proxy/registry yada yada. But maybe the learning curve was just easier at that point, having then already used Spring for lots of other things - YMMV.

  • I need to run multiple external programs concurrently using RMI objects.

    have a web based solutiion which uses a backend machine for some processing. I have a RMI based Java proram running on the backend machine and the web server talks with this backend machine through RMI. Now, on this backend machine, I need to call some external program using Process s = Runtime.getRuntime().exec(....). Since this is a web application, multiple clients will connect at the same time and I need to run this external program for multiple clients at the same time.
    Here is what I do. I have a separate RMI object bound to registry for each client that connects to the web server. This RMI object implements runnable interface, since I can't extend this class from Thread (it already extends from UnicastRemoteObject). So each time I call upon a method from this object, only one process gets started and other objects need to wait till this process finishes.
    I need to start multiple processes at the sametime so that other clients don't have to wait for this thread to finish.
    Please let me know if anybody has any other solution than installing an application server on this backend machine.
    Here is my code.
    public class iLinkOnlineSession extends UnicastRemoteObject implements Session, Serializable, Runnable
      public iLinkOnlineSession(String sessName, String sessId, String rootLogs, String rootWrks) throws RemoteException
        setSessionId(sessId);
        setName(sessName);
        ROOT_LOGS = rootLogs;
        ROOT_WORKSPACE = rootWrks;
        searchKeys_ = new Vector();
        searchObjects_ = new Hashtable();
        Thread s = new Thread(this);
        s.start();
      public void run()
        System.out.println("running");
      public String checkLogin(String user, String passwd)
        String msg = "";
        String cmd = "iLinkOnlineLogin";
        cmd += " param "+ user + " param " + passwd;
        System.out.println("cmd: " + cmd);
        try
          Runtime run = Runtime.getRuntime();
          Process proc = run.exec(cmd);           // Call to the external program.
          InputStream in = proc.getInputStream();
          Reader inp = new InputStreamReader(in);
          BufferedReader rd = new BufferedReader(inp);
          String line = rd.readLine();
          while(line != null)
            System.out.println(line);
            msg += line;
            line = rd.readLine();       
          int res = proc.waitFor();
        }catch(Exception e)
             e.printStackTrace();
        System.out.println("Msg: " + msg);
        return msg;
      public String searchObject(String user, String passwd, String param1, String paramVal1, String param2, String paramVal2, String param3, String paramVal3, String relLev, String mfgLoc)
        String cmd = "iLinkOnlineSearch";
        cmd += " param " + user + " param " + passwd + " param " + getSessionId() + " param " + logFile_ + " param " + param1 + " param " + paramVal1 +
              " param " + param2 + " param " + paramVal2 + " param " + param3 + " param " + paramVal3 + " param "
              + relLev + " param " + mfgLoc;
        System.out.println("cmd: " + cmd);
        try
          Runtime run = Runtime.getRuntime();
          Process proc = run.exec(cmd);                // External program.
          InputStream in = proc.getInputStream();
          Reader inp = new InputStreamReader(in);
          BufferedReader rd = new BufferedReader(inp);
          FileWriter out = new FileWriter(resultFile_);
          System.out.println("Filename: "+resultFile_);
          BufferedWriter wout = new BufferedWriter(out);
          String line = rd.readLine();
           while(line != null)
            System.out.println(line);
            wout.write(line);
            wout.newLine();
            wout.flush();
            line = rd.readLine();
          int res = proc.waitFor();
          wout.close();
          if(res == 0)
            boolean ret = createResultTable();
            if(ret == true)
              return GlobalConstants.SUCCESS_MSG;
            else
              return GlobalConstants.ERROR_MSG;
        }catch(Exception e)
                e.printStackTrace();
        System.out.println("getting results");
        return GlobalConstants.ERROR_MSG;
      }

    I guess I don't get it.
    RMI servers are inherently multi-threaded, so why are you running separate servers for every client?

  • Slow performance when running Multiple programs at once

     When I try to run 2 or 3 programs at once like converting some video and watching something on I tunes My A205-S6808 throws a Fit any Ideas I have already upgraded the memory to 4gigs 

    Satellite A205-S6808
    Some tips..
       Get maximum performance from Windows Vista
       Optimize Windows Vista for better performance
       Ways to improve your computer's performance
    -Jerry

  • Once running the labview program which contain DAQ Assistant ,the message of "ERROR-50405....." appear.

    Once running the labview program which contain DAQ Assistant and can be run without any error before, the message box of "ERROR-50405....." appear which capture down in the attachment. We use PCI6221 and LabVIEW 8.0 in Windows XP. I also found that the Device Manager of Window have recognized the PCI6221.
    Any help on this situation would be great.
    Attachments:
    labview error.JPG ‏145 KB

    Hi~
    This error is due to signal interference between the device and the computer. This could be environmental or due to the PCI Controller. You can on a different computer to see whether this problem persists.

  • Running a java program from an icon

    I want to run my program from an icon on my desktop. I have a .bat file that I've built a shortcut to and it works.MY GUI program does display and run when I click on the icon. The problem is that the DOS window also shows up behind my GUI.
    Is there anyway to prevent the DOS window from showing? Or is there another way to run a Java program without resorting to a DOS command line or running it through FORTE or another IDD?

    Chris's solution worked well, with one small problem. Once my GUI starts, it takes up the whole screen. Normally when I run it, it appears as a small window.
    not a big problem, I can reduce it easily after it starts. But does anyone know a way to make it come up in the reduced size it norally comes up in when I run it from my IDE?

  • Can I run two separate versions of the LabVIEW Run-Time Engine on one PC?

    Hello, I am curious if anyone knew if it is possibly to install and use two separate versions of the LabVIEW Run-Time Engine on one PC?  I currently have the 2009 Run-Time Engine installed on one machine and wanted to install the 2011 Run-Time Engine as well. I know that you can run two separate versions of the LabVIEW program on one machine, but what about the Run-Time Engine?
    Thanks!
    Solved!
    Go to Solution.

    I'm guessing this is a bug that NI needs to fix.  I see no reason you shouldn't be able to install the run-time engine of an older version.  I'd be interesed in if it allows you to install the older development environment, which also includes the older run-time engine.  There are some command line switches for NI installers as mentioned here:
    http://digital.ni.com/public.nsf/allkb/C361087EE9F20810862577850073128E
    I wonder if there is a force install option.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Unable to run a java program...

    Hi.
    I am trying to run a server program that I have implemented, but I'm having some trouble. When I click on the run button, I get the following pop-up message:
    Could not find the main method. Program will exit!
    On the console it says the following:
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Below is the beginning portion of my server class:
    public class JamServer
         public int groupNum = 0;
         int serverPort = 9876;
         private ServerSocket ss;
         //list of client handling threads
         //Vector handlers;
         //list of users
         public Vector users;
         public void main(String args[]) {
         try{
              ss = new ServerSocket(serverPort);
              while(true){
              Socket s = ss.accept();
              User usr = new User();
              usr.setOutput(new DataOutputStream(s.getOutputStream()));
              //users.add(usr);
         new JamServerThread(this,s,usr);
         }catch(IOException e){
              System.err.println("Could not listen on port: "+ serverPort);
              System.exit(-1);
    Does anyone have any idea why it would say it could not find the main method? It's clearly there. Please help!!
    Thanks in advance.

    To further explain, main must be static if you want the JVM to exedute it. Without the static keyword, your main method is simply another instance method which can only be accessed once you have an instance of your class. Static methods can be accessed without instanciating the class. So, the JVM expects to find a method called "main" that is both public and static, takes a String array and returns void.
    HTH

  • Need help with running a Java program on Linux

    I am trying to get a Java program to run on a Linux machine. The program is actually meant for a Mac computer. I want to see if someone with Java experience can help me determine what is causing the program to stall. I was successful in getting it installed on my Linux machine and to partially run.
    The program is an interface to a database. I get the login screen to appear, but then once I enter my information and hit enter the rest of the program never shows, however, it does appear to connect in the background.
    Here is the error when I launch the .jar file from the command screen:
    Exception in thread "main" java.lang.IllegalArgumentException: illegal component position
    at java.awt.Container.addImpl(Unknown Source)
    at java.awt.Container.add(Unknown Source)
    I am not a programmer and I am hoping this will make some sense to someone. Any help in resolving this is greatly appreciated!

    Well, without knowing a little bit about programming, and how to run your debugger, I don't think you're going to fix it. The IllegalArgumentException is saying that some call does not like what it's getting. So you'll have to go in an refactor at least that part of the code.

  • I start running a java program and when i switch users the sound doesnt work

    When I start running a java program or leave a game running and i switch users the sound doesnt work. I have been searching around the web and nobody seems to have an answer. This just recently started to happen. Please if anyone has any ideas that would be much appreciated and the problem is my computer its almost brand new. And my computer is completely up to date.

    Sony Mobile team has a separate community which can be found here.
    If my post answers your question, please click on "Accept as Solution"

  • How to run a java program in windows 2003 server from unix server.

    Hi ,
    I want to run a java program in windows 2003 server from unix machine ..
    will RMI helps me to obtain this.
    Please tell me the procedure to do this.
    Thanks in advance,

    rmi,web services,corba,web 2.0,xml,xls,dtd,rss,ruby on rails,https,soap,tags,blog,podcast,google

  • Can we run multiple sapinst programs in parallel?

    We are planning to upgrade our EP, XI and BW simultaneously. These SIDs all reside on the same server and same OS. Is it possible to run multiple sapinst programs in parallel? I know it may require specifying separate ports for the 2nd and 3rd instance of sapinst. For example: sapinst 1 gets default ports 21212, 21213. sapinst 2 will take 21214, 21215 and sapinst 3 takes 21216 and 21217.
    Has anyone attempted this sort of a thing before? Appreciate your thoughts.

    Never done that before, maybe it works .. however it could run into problems when the sapinst are trying to access the same paths / files.
    Regards,
    Siddhesh

  • How to run a ABAP Program in Batch JOB

    How to run a ABAP Program in Batch JOB ?

    Hello Manish,
    Using transaction SM36 you can define the batch job along with the start conditions for that job.
    1. Transaction SM36.
    2. Give the Z name of the job in the 'Job Name' input field.
    3. Click on 'Steps' button from the application toolbar.
    4. On the 'Create Step 1' dialog box, give the name of the ABAP program in the 'ABAP Program' section' along with the variant.
    5. Click on 'Check Input' button from the dialog box.
    6. Click on 'Save' button from the dialog box once the check is successful.
    7. One list will be shown. Click on Back button from the standard toolbar.
    8. Click on 'Start Conditions' button from the application toolbar. Specify the start condition e.g. immediate. Click on save.
    9. The job staus is now scheduled.
    10.Click on Save button from the standard toolbar of SM36. The job status will be released.
    Using SM37 you can monitor the status of the job.
    This will sort out your problem.
    PS If the answer solves your query, plz reward points.
    Regards

  • Auto Tune prior to running motion control program (LabVIEW)

    Hi,
    I am controlling Parker Compumotor (404-LXR) linear servo table via GV6 drive and PCI-7344 motion controller.
    The problem is that I always have to run automatic tuning in MAX when I turn off all the system and restart it.
    Before I use the automatic servo tuning in MAX, the servo table buzzes and oscillates wildly. Cabling seems to be successful as linear servo motor is completely controlled by LabVIEW after auto tuning in MAX.
    I wonder how I can just run my LabVIEW program without running Auto Tune step.

    Hello Gino,
    Thank you for using our discussion forums. Yes, you can programmatic load the PID parameters from LabVIEW. Tune your servo using auto tune, once you are satisfied with the response look under the Control Loop tab for the PID parameters. In LabVIEW use the Load All PID Parameters.flx and use the tuned parameters from Measurement and Automation Explorer as the PID Parameters input for this VI. Place the VI before the multistart.vi. This will make sure the correct PID settings are used. I hope this helps you out. Have a nice day!
    Regards,
    Nipun M
    Applications Engineer
    National Instruments

  • Prevent running the same program twice or more + some other..

    Hi All,
    I'm trying to figure out how to do the following
    1) How can I prevent a user from running the same program more than once.
    2)If a user try to shut down the computer while my program is running, I need to trap it down and save some data before terminating the program, how can I do it?
    Can any one help me???
    thanks a lot in advance!

    Don't [url http://forum.java.sun.com/thread.jspa?threadID=699067]cross post.
    Answers in the other post please.

Maybe you are looking for

  • File content conversion: nodes have multiple occurence and is jumbled

    Hi, Here is one structure used in file content conversion. Header Dataline1 Dataline1 Dataline1 Dataline2 Dataline2 Dataline2 Header, Dataline1 and Dataline2 are nodes containing more than one fileds. We have mentioned 'fieldSeparator', 'EndSeparator

  • Major bugs in oracle 11g 11.1.0.7??

    Hii All, We are planning to upgrade to 11g currently we are using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE    10.2.0.4.0      Production TNS for Solaris: Version 10.2.0.4.0 - Product

  • How do I get my dsl from century link modem to airport extreme?

    How do I get my dsl from century link modem to airport extreme?

  • If number is not negative

    I want an if statement to do the following If (x is not neagaitve) Do this. eg. If (x!= -n) //where n can be one of an array of numbers Do this. Can anyone help with the "if statement". Cheers, Enda.

  • Entourage: "Event and computer time zones do not match."

    Since installing the latest update to the Mac OS (10.4.6) I have a glitch with Entourage (Office 2004 for Mac v. 11.2.3) and I believe it has something to do with the Mac OS. See below for explanation: When adding a new calendar event to the calendar