From: "Gustavo Guillermo Pérez" <gustavo@compunauta.com>
To: mgc@tid.es, linux-admin@vger.kernel.org
Subject: Re: launching a java application in background
Date: Thu, 3 Feb 2005 15:16:09 +0000 [thread overview]
Message-ID: <200502031516.09482.gustavo@compunauta.com> (raw)
In-Reply-To: <4200FED4.20007@tid.es>
El Miércoles, 2 de Febrero de 2005 16:24, escribió:
> 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 deal with this I change on my Java applications, the System.out.* By calls
to other kind of OUT, then you can make a simple pointer by default from
System.out, System.err, or substitute this by file output, then you can pass
an extra argumento to your software to log by default on a file, and use the
same object (could be static code).
Java have a mechanism to put a thread on a background, in daemon mode, you
should find more about. Here is an example how I use an objet to have
properties, like out, and err, you can establish a socket, or open a file for
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érez
* @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=0;
public boolean BIGFAILURE=false;
public boolean DEBUG=false;
public boolean CHILDREN_MODE=false;
public boolean STOP=false;
public PrintStream out=System.out;
public PrintStream err=System.err;
public static String WORK_DIR="./";
public Properties p=(Properties)null;
public static Properties sp=new Properties();
public static Hashtable h=new Hashtable(10);
public BufferedReader in=new BufferedReader(new
java.io.InputStreamReader(System.in));
public RunTimeManager(){}
public RunTimeManager(boolean debug){this.DEBUG=debug;}
public RunTimeManager(boolean debug,boolean standalone)
{this.DEBUG=debug;this.CHILDREN_MODE=!standalone;}
public void setChildren(boolean value){CHILDREN_MODE=value;}
public void setStandAlone(boolean value){CHILDREN_MODE=!value;}
public void setChildren(){CHILDREN_MODE=true;}
public void setStandAlone(){CHILDREN_MODE=false;}
public boolean VERVOSE=true;
public boolean exit(int EXIT_CODE){
this.EXIT_CODE=EXIT_CODE;
this.STOP=true;
if (EXIT_CODE!=0){BIGFAILURE=true;}
if (CHILDREN_MODE) return true;
else System.exit(EXIT_CODE);
return false;
}//end exit
public void reset(){
this.BIGFAILURE=false;
this.EXIT_CODE=0;
this.STOP=false;
}//end reset
public void setOut(PrintStream out){
this.out=out;
}//end out
public void setErr(PrintStream err){
this.err=err;
}//end err
public void setIn(BufferedReader in){
this.in=in;
}//end err
public void setPropertiesFromHash(String Key){
Object ob=h.get(Key);
Properties p;
if (ob==null) {p=new Properties();h.put(Key,p);}
else {p=(Properties)ob;}
}//end setpropfromhash
public void setDebugOn(){this.DEBUG=true;}
public void setDebugOff(){this.DEBUG=false;}
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=p.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=new REQManipulation(System.getProperty("os.name"));
String env=System.getProperty("os.name");
// System.out.println(System.getProperties());
if (env.toLowerCase().indexOf("linux")!=-1) return "l";
if (env.toLowerCase().indexOf("windows")!=-1) return "w";
if (env.toLowerCase().indexOf("sol")!=-1) return "s";
return "w";
}//end getEnvironOs
}//end class
--
Gustavo Guillermo Pérez
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
prev parent reply other threads:[~2005-02-03 15:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-02 16:24 launching a java application in background Miguel González Castaños
2005-02-03 15:16 ` Gustavo Guillermo Pérez [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200502031516.09482.gustavo@compunauta.com \
--to=gustavo@compunauta.com \
--cc=linux-admin@vger.kernel.org \
--cc=mgc@tid.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.