This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Just wondering how people disconnected their clients when they are calling the server? I know System.exit(o) terminates the virtual machine, but if one was running the application locally, where server and client running, wouldn't System.exit(0) terminate the server as well as the client if I called it from the client? If I run the application locally, aren't the server and client running in the same virtual machine? Any help appreciated.
If you are running in standalone mode there is no use in running any server (you are even violating one of the must requirements i believe if you don't bypass your network code).
I used System.exit(0) when user clicks on the Quit menu-item in my client application (same one is used for both standalone and network mode).
Thanks for your reply. Does this mean in standalone mode, one must know if server is already running? Shouldn't one be able to run both the server and client on the same machine? Or does 1 just assume the server and client are not required to run on the same machine, as it is not a must requirement? Roel, you probably have answered what I have asked above, I just want to confirm the other question parts.
Thanks very much.
In standalone mode there is no server. Your gui will talk to your data class directly (or through a business service implementation). Your complete application will run in the same VM. When your application starts you have to provide just the path to the database file you want to use.
In network mode you have a server. Your gui will talk to your server (via RMI for example and then you need a remote interface. This remote interface can expose business methods like book and search, or could expose the lock, update, unlock methods). The server will talk to your data class. On a computer in your network you will have the server (application) running in a VM. at startup of your server application you'll have to provide the path to the database file you want to use + the port the server will be running on. On (the same or) another computer in your network you will have the client (application) running in a VM (this VM is always another one than the one of your server application, even if server and client run on the same computer). at startup of your client application you'll have to provide the ip (or hostname) of the computer the server is running on + the port the server is running on.
Mark O' Sullivan
Joined: Aug 17, 2009
Thanks for your reply Roel. My problem is with the understanding of what a JVM I think. I thought that if a client and server run on a machine they share the same JVM, thought my understanding here could be wrong. So, for example:
(1) A server is started on 1 machine.
(2) The network client is started on same machine and accessed the server code through the network code.
Does (2) mean the client and server are treated as being in different JVM's because of the network code or do they share the same JVM still? Sorry, it's my understanding of JVM in local mode which is issue really. I understand if accessing each other across network, they are in different JVM's.
and the client application will start in networked mode in another JVM.
Each time you start a java program by calling the java.exe a Java runtime environment is started and your java program is running in this runtime environment. You will see in the processes view (in the windows task manager) a java.exe process for each application you started. More info about the java.exe can be found here
Mark O' Sullivan
Joined: Aug 17, 2009
Thanks for explanation. Understand that now.