UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2005-04-28 01:51 PM

ineo
Member
From: Zion
Registered: 2004-11-28
Posts: 22

Re: Server shutdown

How do you shutdown a server in Java?
For that matter how do you write a daemon in Java?


The problem is choice!

Offline

#2 2005-04-29 02:26 AM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Server shutdown


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#3 2005-04-29 04:13 AM

ineo
Member
From: Zion
Registered: 2004-11-28
Posts: 22

Re: Server shutdown

So are there any Servers you know of that are written in Java completely?
If their Open Source that would be great. And not too greatly advanced. :)


The problem is choice!

Offline

#4 2005-04-29 08:13 AM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Server shutdown

Again, at least that I know of...

There are no pure Java solutions since every platform seems to handle things such as the terminal, users, groups and etc. differently...  some such as MS-Dos don't even have a concept of the latter items... which is rational behind just giving you the URL for the combo Java / native code previously...

Still don't know what platform you are working on... but just for putting something in the background on a *NIX type system... and note it still requires some shell commands... you could try:

nohup java -jar foo.jar </dev/null >>/dev/null 2>>/dev/null &

The nohup will disconnect the JVM from the console so that if the user logs out of the terminal it will continue running i.e. it will ignore the terminal hang up signal...

The center is of course the java command you want to run...

The three /dev/nulls represent standard input, output and error streams and can be changed to any file names... the given one assumes you want to just throw out / disconnect them...

The final & says to run it all in the background...


There is also the daemon command... but in my experience the nohup seems to be universally available...


I didn't ask before ... but on the shutdown side of things...

If you are just looking for "clean up" code for your application / server... the Runtime.getRuntime().addShutdownHook( Thread hook ) allows you to do that...



Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#5 2005-04-29 08:27 AM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Server shutdown

Just a heads up in case the question arises... the java.lang.Process class / objects don't really work for this either...

A direct quote from the current API docs:

"The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts."

So creating a new Process using the Runtime or ProcessBuilder doesn't seem to be a cure... 


Also... the threadObj.setDaemon( true ) call cannot be used as a single step solution... since the JVM explicitly states that when all threads are daemons the JVM will exit...


Not trying to be the bearer of bad news... but I have gone through the same thing in the past myself... and its just one of the things you have to live with when writing this type of program in Java...


Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#6 2005-04-29 12:54 PM

ineo
Member
From: Zion
Registered: 2004-11-28
Posts: 22

Re: Server shutdown


The problem is choice!

Offline

#7 2005-04-29 01:35 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Server shutdown


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#8 2005-04-29 01:42 PM

ineo
Member
From: Zion
Registered: 2004-11-28
Posts: 22

Re: Server shutdown

So you mean to say that I will need a binary helper for each platform?


The problem is choice!

Offline

#9 2005-04-29 01:42 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: Server shutdown

Offline

#10 2005-04-29 02:03 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Server shutdown

>> Ignoring Rob <<

:-P


Yes, for this particular situation you will need a binary helper...


Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#11 2009-01-01 05:25 PM

lilokster
Guest

Re: Server shutdown

I don't think there are any servers written completely in Java.

#12 2009-12-16 04:37 PM

Naguellegange
Guest

Re: Server shutdown

I am trying to install the Flash chat using either PHP or Java Socket.

None of the instructions provided in this forum or in the documentation itself matches what I see in my newly downloaded demo.

For example, I do not have patServer folder. I do not have the a line:

enableSocketServer => true,

in inc/config.php

So since nothing matches the docs or the forum, I am not sure how to get the socket server running?

Also, does the Java socket server option need to be started with a shell command as well?

Can the PHP socket service be left on? Is there an option where the socket server is started and killed automaticaly?

Board footer

Powered by FluxBB