launching a java application in background
am 02.02.2005 17:24:52 von mgc
Dear all,
I need to launch a java proccess as a daemon, in background.
It would be like the following:
java bin/aplicacion.jar
In interactive mode works fine. We have tried to launch it in background
using nohup.
If I send everything (all redirections <> ) to /dev/null it works, but I
do not get the logs
We have tried:
java bin/aplication.jar < /dev/null > output.log 2>&1 &
But I get in the output file carachters like "->"
Any time of getting those logs?
I hope I have explained myself fine
Regards
Miguel
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: launching a java application in background
am 03.02.2005 00:00:06 von unknown
El Mi=E9rcoles, 2 de Febrero de 2005 16:24, escribi=F3:
> Dear all,
>
> I need to launch a java proccess as a daemon, in background.
>
> It would be like the following:
>
>
> java bin/aplicacion.jar
>
> In interactive mode works fine. We have tried to launch it in backgro=
und
> using nohup.
>
> If I send everything (all redirections <> ) to /dev/null it works, bu=
t I
> do not get the logs
>
> We have tried:
>
> java bin/aplication.jar < /dev/null > output.log 2>&1 &
>
> But I get in the output file carachters like "->"
>
> Any time of getting those logs?
>
> I hope I have explained myself fine
>
> Regards
>
> Miguel
To deal with this I change on my Java applications, the System.out.* By=
calls=20
to other kind of OUT, then you can make a simple pointer by default fro=
m=20
System.out, System.err, or substitute this by file output, then you can=
pass=20
an extra argumento to your software to log by default on a file, and us=
e the=20
same object (could be static code).
Java have a mechanism to put a thread on a background, in daemon mode, =
you=20
should find more about. Here is an example how I use an objet to have=20
properties, like out, and err, you can establish a socket, or open a fi=
le for=20
writing and you can set the new output calling setOut or setErr.
------------------
package com.compunauta.util;
/**
* Title: RUNTimeManager
* Description: OUT, ERR, PROPERTIES, handler for threads.
* for html parser.
* Copyright: Copyright (c) 2001
* Company: www.compunauta.com
* @author Gustavo Guillermo P=E9rez
* @version 1.0
*/
import java.io.PrintStream;
import java.io.BufferedReader;
import java.util.Properties;
import java.util.Hashtable;
public class RunTimeManager {
public int EXIT_CODE=3D0;
public boolean BIGFAILURE=3Dfalse;
public boolean DEBUG=3Dfalse;
public boolean CHILDREN_MODE=3Dfalse;
public boolean STOP=3Dfalse;
public PrintStream out=3DSystem.out;
public PrintStream err=3DSystem.err;
public static String WORK_DIR=3D"./";
public Properties p=3D(Properties)null;
public static Properties sp=3Dnew Properties();
public static Hashtable h=3Dnew Hashtable(10);
public BufferedReader in=3Dnew BufferedReader(new=20
java.io.InputStreamReader(System.in));
public RunTimeManager(){}
public RunTimeManager(boolean debug){this.DEBUG=3Ddebug;}
public RunTimeManager(boolean debug,boolean standalone)
{this.DEBUG=3Ddebug;this.CHILDREN_MODE=3D!standalone;}
public void setChildren(boolean value){CHILDREN_MODE=3Dvalue;}
public void setStandAlone(boolean value){CHILDREN_MODE=3D!value;}
public void setChildren(){CHILDREN_MODE=3Dtrue;}
public void setStandAlone(){CHILDREN_MODE=3Dfalse;}
public boolean VERVOSE=3Dtrue;
public boolean exit(int EXIT_CODE){
this.EXIT_CODE=3DEXIT_CODE;
this.STOP=3Dtrue;
if (EXIT_CODE!=3D0){BIGFAILURE=3Dtrue;}
if (CHILDREN_MODE) return true;
else System.exit(EXIT_CODE);
return false;
}//end exit
public void reset(){
this.BIGFAILURE=3Dfalse;
this.EXIT_CODE=3D0;
this.STOP=3Dfalse;
}//end reset
public void setOut(PrintStream out){
this.out=3Dout;
}//end out
public void setErr(PrintStream err){
this.err=3Derr;
}//end err
public void setIn(BufferedReader in){
this.in=3Din;
}//end err
public void setPropertiesFromHash(String Key){
Object ob=3Dh.get(Key);
Properties p;
if (ob==null) {p=3Dnew Properties();h.put(Key,p);}
else {p=3D(Properties)ob;}
}//end setpropfromhash
public void setDebugOn(){this.DEBUG=3Dtrue;}
public void setDebugOff(){this.DEBUG=3Dfalse;}
public void setProperty(String Key, String Value){
if (this.p==null){sp.setProperty(Key,Value); return;}
this.p.setProperty(Key,Value);
}//end setproperty
public String getProperty(String Key, String Default){
if (this.p==null){return sp.getProperty(Key,Default);}
else {String ob=3Dp.getProperty(Key,Default);
if (ob==null){
return sp.getProperty(Key,Default);
}else return ob;
}
}//end getProperty
public String getProperty(String Key){
return getProperty(Key,null);
}//end getProp
public static String getEnvironOs(){
//REQManipulation env=3Dnew REQManipulation(System.getProperty("os.name=
"));
String env=3DSystem.getProperty("os.name");
// System.out.println(System.getProperties());
if (env.toLowerCase().indexOf("linux")!=3D-1) return "l";
if (env.toLowerCase().indexOf("windows")!=3D-1) return "w";
if (env.toLowerCase().indexOf("sol")!=3D-1) return "s";
return "w";
}//end getEnvironOs
}//end class
--=20
Gustavo Guillermo P=E9rez
Compunauta uLinux
www.ulinux.tk
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html