Hi,

I have implemented a simple socket server in Java. Everything works great except the process just dies/times out after about an hour and I do not know why. I run am running the process through my web host's machine using SSH.

My steps:
1. Add to '/etc/rc.local' two commands: 'cd /path/to/.classname' and 'java .classname'
2. Reboot and check process with 'ps -A' and see my 'java' process running. Everything's good.
3. check back periodically and note that after about an hour 'java' process simply disappears

There could not be a crash because no clients were connecting during that time. The process was just sitting and blocking at ssock.accept();

I tried ssock.setSoTimeout(0) but it doesn't help.

Any ideas? Perhaps JVM killing it?

Thanks,
Max

Redirect STDERR and STDOUT to a file and see what shows up there, first. You can't diagnose anything without gathering any information.

Redirect STDERR and STDOUT to a file and see what shows up there, first. You can't diagnose anything without gathering any information.

I have a massive log (wiriting to text file) going throughout my application. but 95% of my application is handling client communication, however the process dies in the .accept() method, which is inside an infinite loop, before any client connection is made. I log data in the exception but there's really no other place for the program to run. Given, the infinite loop and no client connections, it really seems like something external is killing it. Here's the code

while (true) 
	    {
	    	Socket sock=null;

			try {
//dies here.....
				sock = ssock.accept();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				try {
					log2.write(e.toString());
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			System.out.println("Connected");
			new Thread(new MIL(sock)).start();
	    }

..appreciate your help.

To quote masijade "You can't diagnose anything without gathering any information."
- If you suspect it's something external, check the OS logs.
- In case of unhanlded signals (IOW process crash) you might have heapdumps. Look for them.
- At the very least add logs before and after accept().
- Try registering for signals if that turns out to be the problem.

To quote masijade "You can't diagnose anything without gathering any information."
- If you suspect it's something external, check the OS logs.
- In case of unhanlded signals (IOW process crash) you might have heapdumps. Look for them.
- At the very least add logs before and after accept().
- Try registering for signals if that turns out to be the problem.

Thanks. I will try some of these suggestions.

So what does

e.printStackTrace();

and

log2.write(e.toString());

produce?

Edit: P.S. Change

log2.write(e.toString());

to

log2.write(e.getClass() + ":  " + e.toString());

I wasn't able to get to the bottom of this. The workaround was to add a line to "/etc/inittab" which autospawns my application-starting script. My java server has been running acceptably well for 5 months now.

Thanks for everyone's help.

Well, maybe if you had provided us with the actual error messages, we might have been able to solve it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.