Logging api hangs

Im starting a java application from an applet calling Runtime.getRuntime().exec("java bla bla bla")
Worked fine until I implemented Java 1.4 logging api. Now the application hangs after writing a few info lines to a FileHandler log. It's clearly the logger that hangs because if I set log level = OFF the the program runs just fine.
Has anyone seen anything similar?
* To make it harder to debug, the problem only occurs when starting the application from an applet.

That might happen that spawn process generates lots of output.
Runtime.getRuntime().exec() returns object of type java.lange.Process. That object provide access to the stdout and stderror of the newly created process. If those streams are not cleaned properly then process will hang as soon as OS buffers of those stdout and stderr streams get full.
One way to work around it just read output from the process and throw it away. You can try using something like this:
package com.xxx;
import java.io.InputStream;
public class ProcessOutputWaster {
    public ProcessOutputWaster(Process process)
        throws Exception {
        createWorker(process.getErrorStream()).start();
        createWorker(process.getInputStream()).start();
    protected Worker createWorker(InputStream is) {
        return new Worker(is);
    protected static class Worker
              extends Thread {
        private InputStream inputStream_;
        public Worker(InputStream inputStream) {
            inputStream_ = inputStream;
        public void run() {
            if (getInputStream() != null) {
                try {
                    byte[] buffer = new byte[1024];
                    int read;
                    while(true) {
                        read = inputStream_.read(buffer);
                        if (read < 0)
                           break;
                catch(Exception ex) {
                    Handle the error some how. E.g. show the error box.
Process process = Runtime.getRuntime().exec(strCommand);
ProcessOutputWaster outputWaster = new ProcessOutputWaster(process);

Similar Messages

  • Practical use of Java Logging API

    There was a recent technical tip about the Java Logging API, but after reading it I still don't understand how to use it in a real situation.
    Can anyone help me with this with a practical example?
    At the moment I have try-catch clauses that catch exceptions and print a message in a System.err log that I can consult if there's a specific problem.
    How should I be using the Logging API? I feel sure that it can help me, but can't see how.
    Thanks for any practical information.

    What if you don't want to write to system.err anymore? What if you need to write something to the windows event log? What if system.err is irrelevant (nt service), ...
    Btw, lots of examples on the JDK1.4 logging api:
    http://www.esus.com/docs/GetIndexPage.jsp?uid=265

  • How to set NC Log API

    Hi all,
    I want to use the following NC log API,but I don't know how to initialize the interface's java object and set the parameter "ApplicationVO".
    Interface LogNCApplicationInterface
    Method ApplicationVO addNDone(ApplicationVO applicationvo)
    Please help me.Thank you!
    Qiang Liu

    if you just need to log an NC the minimum fields you need to set are the following:
    CreateNCRequest ncRequest = new CreateNCRequest();
    ncRequest.setActivity("NC500"); // activity where NC is logged - can be any name
    ncRequest.setSfcRef(new SFCBOHandle(site, sfcParent).toString());// the SFC for which you are reporting an NC
    // ncRequest.setValidateNCCodeOperation(true); // no need to set it, it's true by default
    // nc code reference for nc code that is reported
    // nc code must exist in the system
    ncRequest.setNcCodeRef(new NCCodeBOHandle(site,"NCCODE").toString());
    // required custom fields must be set
    CreateNCResponse ncResponse = ncPSI.createNC(ncRequest);

  • Setting Logging API config file

    Hi,
    Is there a way I can set the Logging API's config file (java.util.logging.config.file) from within my program? I have tried using System.setProperty but it doesn't seem to work. The only way I seem to be able to set the property is with -D on the command line.
    Thanks
    Rob

    Is there a way I can set the Logging API's config file (java.util.logging.config.file) from within my program? I have tried using System.setProperty but it doesn't seem to work. The only way I seem to be able to set the property is with -D on the command line.Read the Logging Overview Dokumentation
    anyway
    InputStream inputStream = new FileInputStream("logging.properties");
    LogManager.getLogManager().readConfiguration(inputStream);
    ...

  • Logging API AdapterFramework 3.0

    Hello,
    i still wonder why it was necessary to provide an own API for Logging and Tracing inside the Adapter Framework.
    The Web AS Logging API does the same.
    Developing an JCA Adapter that can be used inside the XI Adapter Framework and as a Basic JCA 1.0 Adapter in the Web AS, theres's need to provide support for both APIs.
    Has anyone an idea to solve this problem?

    There is a lot of logging to the console with 2.3.0 RC1 when I am doing
    any trips to the datastore, is it possible to switch this off? I am
    using Kodo.rar in Jboss 3.0.0Remove the 'com.solarmetric.kodo.Logger' property from your properties file. You can also remove it from the Properties instance you use to construct the PersistenceManagerFactory. If you'd like to log to a file instead, change the property to the name of a file to log to.

  • Forum help for Logging api

    I need help with logging api. Which developer forum do I have to use for the same. Thanks.

    Have you got the SAP Wrapper for logging API? if you got, can you give it to me:)

  • Is this logging code faster than using a standard logging API like log4J

    is this logging code faster than using a standard logging API like log4J or the logging API in java 1.4
    As you can see my needs are extremely simple. write some stuff to text file and write some stuff to dos window.
    I am thinking about using this with a multi threaded app. So all the threads ~ 200 will be using this simultaneously.
    * Tracer.class logs items according to the following criteria:
    * 2 = goes to text file Crawler_log.txt
    * 1 = goes to console window because it is higher priority.
    * @author Stephen
    * @version 1.0
    * @since June 2002
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    class Tracer{
    public static void log(int traceLevel, String message, Object value)
    if(traceLevel == 1){
    System.out.println(getLogFileDate(new Date()) +" >" + message+ " value = " + value.toString()););
    }else{
    pout.write(getLogFileDate(new Date()) +" >" + message + " value = " + value.toString());
    pout.flush();
    public static void log(int traceLevel, String message )
    if(traceLevel == 1){System.out.println(message);
    }else{
    pout.write(message ) ;
    pout.flush();
    //public static accessor method
    public static Tracer getTracerInstance()
    return tracerInstance;
    private static String getLogFileDate(Date d )
    String s = df.format(d);
    String s1= s.replace(',','-');
    String s2= s1.replace(' ','-');
    String s3= s2.replace(':','.');
    System.out.println("getLogFileDate() = " + s3 ) ;
    return s3;
    //private instance
    private Tracer(){
    System.out.println("Tracer constructor works");
    df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    date = new java.util.Date();
    try{
    pout = new PrintWriter(new BufferedWriter(new FileWriter("Crawler_log"+getLogFileDate(new Date())+".txt", true)));
    pout.write("**************** New Log File Created "+ getLogFileDate(new Date()) +"****************");
    pout.flush();
    }catch (IOException e){
    System.out.println("**********THERE WAS A CRITICAL ERROR GETTING TRACER SINGLETON INITIALIZED. APPLICATION WILL STOP EXECUTION. ******* ");
    public static void main(String[] argz){
    System.out.println("main method starts ");
    Tracer tt = Tracer.getTracerInstance();
    System.out.println("main method successfully gets Tracer instance tt. "+ tt.toString());
    //the next method is where it fails - on pout.write() of log method. Why ?
    tt.log(1, "HIGH PRIORITY");
    System.out.println("main method ends ");
    //private static reference
    private static Tracer tracerInstance = new Tracer();
    private static Date date = null;
    private static PrintWriter pout = null;
    public static DateFormat df = null;
    }

    In general I'd guess that a small, custom thing will be faster than a large, generic thing with a lot of options. That is, unless the writer of the small program have done something stupid, og the writer of the large program have done something very smart.
    One problem with java in this respect is that it is next to impossible to judge exactly how much machine-level processing a single java statement takes. Things like JIT compilers makes it even harder.
    In the end, there is really only one way to find out: Test it.

  • Customize Java logging API

    Want to customize java.util.logging api, like write message to message queue, xml file, etc. Would you guys give me some useful suggestion or resource or link? Thanks.

    Just write a sub-class of Handler such as this:
    public class JMSHandler extends Handler {
    }Look into the JDK source code such as MemoryHandler and StreamHandler on how to implement it.

  • How come logging is so hard? - JDK1.4 Logging API

    Have a small project on hand. A standalone java program trigged by unix cron job and do some data cleaning. Need to implement a very simple logger. Tried to use JDK1.4 Logging API, here's my code:
    public class MyLogManager {
         public final static String NAME = "mylog";
         public final static String LOG_FILE_NAME = "C:/my.log";
         private static Logger logger;
         static {
              try {
                   logger = Logger.getLogger(NAME);
                   Handler fh = new FileHandler(LOG_FILE_NAME);
                   fh.setFormatter(new SimpleFormatter());
                   logger.addHandler(fh);
                   logger.setLevel(Level.ALL);
              } catch (Exception e) {
                   System.out.println("Unable to initialize logger: " + e.toString());
                   System.exit(1);
         public static Logger getLogger() {
              return logger;
    and use MyLogManager.getLogger().info("message") to log message.
    It works and my.log was generated with log message. However, the problem is everytime a new job (java myprogam ...) runs, it deletes the old log file and create a new one.
    I want the message to be appended by the end of old log file. What should I do? Any help?

    Use log4j (google for it - it's on http://jakarta.apache.org).
    If log4j.jar is in your classpath, the JDK 1.4 logging framework will use it automatically. Then all you have to do is to configure a log4j.properties file in your classpath to log wherever you want it to.
    And log4j is sorta-smart about multiple programs logging to the same file.

  • Jdk logging api

    iam using jdk logging api. I've a scenario,
    where there are two subclasses for a parent one.
    is it suffice to use Logger.getLogger("packagename.superclass");
    in the parent class, for all the subclasses to use the same logging medium.
    Thanks

    What happened when you tried that?

  • [svn:osmf:] 14984: Updating to work with the latest logging API changes.

    Revision: 14984
    Revision: 14984
    Author:   [email protected]
    Date:     2010-03-24 07:23:14 -0700 (Wed, 24 Mar 2010)
    Log Message:
    Updating to work with the latest logging API changes.
    Modified Paths:
        osmf/trunk/apps/samples/framework/OSMFPlayer/src/DebuggerLogger.as

    Revision: 14984
    Revision: 14984
    Author:   [email protected]
    Date:     2010-03-24 07:23:14 -0700 (Wed, 24 Mar 2010)
    Log Message:
    Updating to work with the latest logging API changes.
    Modified Paths:
        osmf/trunk/apps/samples/framework/OSMFPlayer/src/DebuggerLogger.as

  • Log4j VS other logging APIs

    I need a logging API for my current application, and I was going to go with log4j. I just wanted to check first to make sure that there were no other more popular loggers, or logging APIs build directly into Java 1.5.
    Thanks for any info,
    John

    Log4j has extensive use within the J2EE community, while java.util.logging is (relatively) new. If you're not sure you'll stick to one or the other, you could use a higher-level API like Apache's commons logging :
    http://jakarta.apache.org/commons/logging/Then you could use whatever logging solution you choose and switch at a later time without impacting your program in a significant way.

  • WLS logging api

    Hi All,
    My app is running on WLS 8.1. I am using WLS logging api to log the messages and
    I also email those messages. I would like to configure the logging so that I can
    send a particular message once every x time interval.
    e.g. If the same error message is thrown multiple times in an hour, currently
    the app will send those many emails. I want to change it so that even though the
    same error message is thrown multiple times in an hour, the app will send only
    one email.
    Is there a way to do this using WLS api?
    Thanks,
    WD

    I did not set up the email messages within WLS 8.1. I have written my own emailer
    class that I use.
    "Sean C. Sullivan" <nospam@spamfree> wrote:
    >
    How did you setup error email messages with BEA Weblogic Server 8.1?
    Can this be setup from the Admin console?
    WD wrote:
    Hi All,
    My app is running on WLS 8.1. I am using WLS logging api to log themessages and
    I also email those messages. I would like to configure the loggingso that I can
    send a particular message once every x time interval.
    e.g. If the same error message is thrown multiple times in an hour,currently
    the app will send those many emails. I want to change it so that eventhough the
    same error message is thrown multiple times in an hour, the app willsend only
    one email.
    Is there a way to do this using WLS api?

  • Logging API

    I am trying to use the logging APIs within a channel's java application code. The code will successfully create the log file, but I can not get it to log any information into that file. Can anyone point me to what I might be missing?
    I am running Portal 6.0 on Solaris 2.9 with JVM version 1.3.1_04.
    Here is the code I am working with, which is more or less right out of the developers guide. When I execute it i get no errors, no exceptions, no data in log file.
    Any help would be appreciated.
    Bill
          try {
                SSOTokenManager manager = SSOTokenManager.getInstance();
                token = manager.createSSOToken(req);
                if (!manager.isValidToken(token)) {
                        message = "*** InValid Token. ***";
          } catch(Exception e){
                        message = "*** SSOToken Exception. ***" + e.toString();
           try {
                      LogManager logger = new LogManager(token);
                      logger.create("SampleLog.log");
                      LogRecord lr = new LogRecord("Session", "Sample Data");
                      logger.write(lr, "SampleLog.log");
            } catch (Exception e) {
                          content.append( "Logging Error: " + e.toString() + "\n");             
            }

    Thanks for your feedback.
    BEA is on the expert group of this JSR and we are tracking this standard.
    We will consider implementing this API in the next release.
    Wong Kok Wai <[email protected]> wrote in message
    news:[email protected]..
    Sun has released the public draft of the Logging API
    (http://java.sun.com/aboutJava/communityprocess/review/jsr047/). Suggest
    for WLS to implement this API, except the package name, to minimise
    porting in future.

  • Does the logging API provide  "Asynchronous File Handler", like log4j ?

    Hi,
    One more question about java.util.logging:
    Does sun provide a standard "Asynchronous File Handler", equivalent to log4j AsyncFileAppender ?
    The idea is, logging requests are placed into a queue, which is being consumed by a dedicated logging-IO thread.
    Thanks.

    it's a shame, really. the Logging API was blatantly inspired by Log4J, but it's just such a poor cousin in so many ways...

Maybe you are looking for

  • IPhoto crashes with slideshow

    Hi, I've installed iPhoto 8.1 on my MacBook (end 2007) and when I want to watch to a slideshow, my screen fades to black and the soft crashes. Then I've the window to relanch the app. I've no idea about the solution... Thanks in advance. Jeff

  • Hardware requirement for SSAS

    We have a requirement to load 50 Billion FACT rows from Netezza in a SSAS Cube . We plan to have a MOLAP cube. Please suggest what should be the ideal SSAS Server hardware requirement to handle this request.

  • Can execute query be controlled for blocks

    Hi, I've 3 blocks in my form. The first and the second block are in query mode, therefore I cannot update, insert, delete values here. The third block, I have put on another canvas. So the moment there's data in the second block the third block gets

  • Laptop crashed, want to re-install on new computer

    Hi there, I had a laptop from new about 4 years ago with Photoshop elements 7 installed. It crashed so I bought the Adobe Photoshop Elements 10 and Premiere Elements 10 bundle and since the laptop crashed again. Now I have this new laptop (as of last

  • Logic Pro 8 and PT 7.4 not compatible ...

    PT 7.4 is out. Having Logic 8 on a MAC PRO as a front end for PTHD was supposed to happen with PT 7.4 release. I downloaded it ($79) trying last night to set Logic 8 in the preference. First I set up the Core audio to my 96i I/o, then selected "DAE".