aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Keep server running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Keep server running" Watch "NX: Keep server running" New topic
Author

NX: Keep server running

Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
I'm embarrassed to ask but how do you keep the server running?

just exits.
With thanks.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Tiger,

just exits.
[/qb]<hr></blockquote>
Well, it shouldn't be exiting. So I suspect it may be terminating due to an unhandled exception (or even worse, a swallowed exception). My suggestion is try the following:

Hope this helps,
George
[ February 15, 2004: Message edited by: George Marinkovich ]

Regards, George
SCJP, SCJD, SCWCD, SCBCD
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
What I meant to say was: the server code runs as above, then returns to its calling method and errors (in my case). The only way I can prevent it from doing that is by - and it works as a "server".
What can I do to make it how it should be? Or is good enough? I suppose I have to re-think my design.
If anybody would help me that would be great.
Thanks in advance.
[ February 16, 2004: Message edited by: Tiger Hilton ]
[ February 16, 2004: Message edited by: Tiger Hilton ]
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Tiger,
Originally posted by Tiger Hilton:
What I meant to say was: the server code runs as above, then returns to its calling method and errors (in my case).

That's what I'm getting at, what is the error you're seeing? You shouldn't need to do the "for( ; ; ) " to keep your server running. If you take it out what happens? What is the error you're seeing?
Hope this helps,
George
[ February 16, 2004: Message edited by: George Marinkovich ]
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
Thanks for your reply George.
The error I'm seeing is a NullPointerException. My design is copied from Max's. (Max's you have to start it by running the method directly from the command line). I didnt read carefully everything in RMI so I'm going to from now on. I'm confused what's the steps to run the server without

and a network client?
Thanks in advance.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Tiger,
Originally posted by Tiger Hilton:
The error I'm seeing is a NullPointerException.

Can you post the stack trace you see when you get the NullPointerException?
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
Here's the stack trace:

Any other information you need just let me know and I'll post it. Sorry about the late reply.
Thanks.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Tiger,
NullPointerExceptions are usually a lot of fun to track down, mostly because where they occur and where they need to be fixed are often totally different places. I think it would be helpful if you posted the code for the GUIController.find method. Even if you don't post it, take a look at line 56 in your GUIController.java file and see if you can identify which object on that line could possibly be null. If you can identify such an object then you'll have to go to where you think it should have been assigned a value and try to figure out under which circumstances that might not happen correctly. The find method is not likely to be the problem, it's just that find is probably the first database operation you call in the client and so that's where a symptom (NullPointerException) of the underlying problem is first expressed.
[ February 19, 2004: Message edited by: George Marinkovich ]
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
Hi George,
To be as pithy as possible what I'm asking is why does my server code NOT stop at:

Shouldn't it stop there?
Thanks in advance.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Tiger,
Originally posted by Tiger Hilton:
Hi George,
To be as pithy as possible what I'm asking is why does my server code NOT stop at:

Shouldn't it stop there?

No. My understanding is that what happens when you rebind the object is that your server listens for requests on the RMI port (1099 if you didn't specify something else). So the client calls the read(recNo) on the database connection. If the database connection is remote (and assuming you're using RMI) then the read(recNo) call ends up sending a request to the RMI port on the database server machine and receiving back a response (in this case String[] containing a database record). So, you want your database server to stay up and running rather than stop.
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
No. My understanding is that what happens when you rebind the object is that your server listens for requests on the RMI port.

So what is the next lines of code or steps that should run after your server starts listening?
Thanks in advance.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Originally posted by Tiger Hilton:

So what is the next lines of code or steps that should run after your server starts listening?

The rebind is basically the last thing my server does. It just sits there running and listening for any activity on the RMI port. The next thing I do is start my application as a network client on another machine and configure it to connect to my database server host and port. The network client ends up doing a registry.lookup() for the remote object that was bound in my server.
I have a nagging feeling that I'm not really answering the question you're trying to ask. Maybe you can ask your question a different way.
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
The rebind is basically the last thing my server does. It just sits there running and listening for any activity on the RMI port.

How do you make it "just sit there running and listening"? Doesn't it exit main() eventually therefore the server stops?
Thanks in advance.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11278
    
  59

Hi Tiger,
Here is a very simple server you should be able to create and confirm that the client does not exit after the rebind:

Copy and paste this code into one file (SimpleClientServer.java). The compile it (javac SimpleClientServer.java) then run the rmic compiler against the RemoteObject (rmic Server).
Then in one window, run the server (java SimpleClientServer). You should see the message telling you that the server has started, but you should not get a command prompt back - the server will continue running.
In another window you can run the same application again (java SimpleClientServer), and you should see some output in the server window.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tiger Hilton
Greenhorn

Joined: Feb 05, 2004
Posts: 11
Thanks Andrew. The code works as you said. I'm going to have to manipulate mine so it works like yours which superficially is exactly the same.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Keep server running
 
Similar Threads
WSDL Exception in IBM WSAD
Question about Server GUI
ace
JApplet - works on windows not on Linux
SQL Server express 2008 jdbc connection problem