Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Navin Ipe
Hi,

I'm using...

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
static Logger logger = LoggerFactory.getLogger(MyClass.class);
Process ps;
ps = Runtime.getRuntime().exec("java -jar myclass.jar");
ps.waitFor();


MyClass is part of a Spring Boot project which uses these dependencies:
dependencies {
  compile "ch.qos.logback:logback-classic:1.1.3"
  compile "ch.qos.logback:logback-core:1.1.3"
  compile "org.slf4j:slf4j-api:1.7.12"


Problem is...
myclass.jar runs fine for a while and I can see the outputs of the logger in myclass.log, but after a few hundred lines, there are no more log outputs visible. Moreover, the program itself doesn't seem to function anymore (the program is supposed to be writing to MySQL) but the program does not quit either. It just appears to hang. I left it for 14 hours like that, and nothing proceeded. There's no while loop after ps.waitFor(), and the code is itself not in an infinite loop. As long as the logs are written to the file, the program also writes to MySQL.

On the other hand, if I switch off logging, the program works fine from start to end, writes to MySQL and completes running in 6 hours and exits fine.

I'm considering writing a small sample program to test it out separately, but considered asking here in case this is a known issue.


--
Regards,
Navin

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Navin Ipe
Confirmed. There is a problem. Even without Spring Boot. Just using logback and slf4j. A very very simple program. It outputs upto i=1146 and then the program hangs.
Why does this happen?

You could try it yourself. The program is given below. You'll be able to build and run the project without gradle too. Just use your favourite build tool like Ant or Maven.

First project:
package com.slh;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class outputter {
   
    private static final Logger logger = LoggerFactory.getLogger(outputter.class);

    public static void main(String[] args) throws InterruptedException, SQLException {       
        logger.info("Outputter started");
        Integer i = 0;
       
        while(true) {
            logger.info("i = {}", i++);
            TimeUnit.MILLISECONDS.sleep(100);
        }
       
    }
}

Gradle build of first project:
apply plugin: 'java'

sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

jar {
 from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }   
    manifest {
        attributes 'Main-Class': 'com.slh.outputter'
    }
}

if (!hasProperty('mainClass')) {
    ext.mainClass = 'com.slh.outputter'
}

repositories {
    mavenCentral()
}

dependencies {
    compile "ch.qos.logback:logback-classic:1.1.3"
    compile "ch.qos.logback:logback-core:1.1.3"
    compile "org.slf4j:slf4j-api:1.7.12"     
    testCompile group: 'junit', name: 'junit', version: '4.10'
}


Second project:
package com.slh;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class outputtercaller {
   
    private static final Logger logger = LoggerFactory.getLogger(outputtercaller.class);
   
    public static void main(String[] args) throws IOException, InterruptedException {
        Process ps;
        logger.info("Running outputter.jar. See the log file");
        ps = Runtime.getRuntime().exec("java -jar outputter.jar ");
        ps.waitFor();
        logger.info("finished running outputter.jar");
    }
}

Second project's gradle build file:
apply plugin: 'java'

sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

jar {
 from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }   
    manifest {
        attributes 'Main-Class': 'com.slh.outputtercaller'
    }
}

if (!hasProperty('mainClass')) {
    ext.mainClass = 'com.slh.outputtercaller'
}

repositories {
    mavenCentral()
}

dependencies {
  compile "ch.qos.logback:logback-classic:1.1.3"
  compile "ch.qos.logback:logback-core:1.1.3"
  compile "org.slf4j:slf4j-api:1.7.12"
   
    testCompile group: 'junit', name: 'junit', version: '4.10'
}


Both programs have their own logback.xml files which look like this:

<configuration>
  <!-- always a good activate OnConsoleStatusListener -->
  <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> 

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>outputter.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>crystal.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
      <maxHistory>10000</maxHistory>
    </rollingPolicy>

    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>
 
 <logger name="com.slh" level="INFO"/>
 
 
  <root level="debug">
      <appender-ref ref="FILE" />
      <appender-ref ref="STDOUT" />     
  </root>
 
</configuration>




On Mon, Jun 27, 2016 at 10:32 AM, Navin Ipe <[hidden email]> wrote:
Hi,

I'm using...

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
static Logger logger = LoggerFactory.getLogger(MyClass.class);
Process ps;
ps = Runtime.getRuntime().exec("java -jar myclass.jar");
ps.waitFor();


MyClass is part of a Spring Boot project which uses these dependencies:
dependencies {
  compile "ch.qos.logback:logback-classic:1.1.3"
  compile "ch.qos.logback:logback-core:1.1.3"
  compile "org.slf4j:slf4j-api:1.7.12"


Problem is...
myclass.jar runs fine for a while and I can see the outputs of the logger in myclass.log, but after a few hundred lines, there are no more log outputs visible. Moreover, the program itself doesn't seem to function anymore (the program is supposed to be writing to MySQL) but the program does not quit either. It just appears to hang. I left it for 14 hours like that, and nothing proceeded. There's no while loop after ps.waitFor(), and the code is itself not in an infinite loop. As long as the logs are written to the file, the program also writes to MySQL.

On the other hand, if I switch off logging, the program works fine from start to end, writes to MySQL and completes running in 6 hours and exits fine.

I'm considering writing a small sample program to test it out separately, but considered asking here in case this is a known issue.


--
Regards,
Navin



--
Regards,
Navin

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Chetan Mehrotra
What happens if you try to disable the ConsoleAppender for outputter.
Probably logs are getting accumulated in the output stream. But the
java code is not draining it out so once it reaches the bugger limit
it gets blocked.
Chetan Mehrotra


On Mon, Jun 27, 2016 at 4:22 PM, Navin Ipe
<[hidden email]> wrote:

> Confirmed. There is a problem. Even without Spring Boot. Just using logback
> and slf4j. A very very simple program. It outputs upto i=1146 and then the
> program hangs.
> Why does this happen?
>
> You could try it yourself. The program is given below. You'll be able to
> build and run the project without gradle too. Just use your favourite build
> tool like Ant or Maven.
>
> First project:
> package com.slh;
> import java.util.concurrent.TimeUnit;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class outputter {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(outputter.class);
>
>     public static void main(String[] args) throws InterruptedException,
> SQLException {
>         logger.info("Outputter started");
>         Integer i = 0;
>
>         while(true) {
>             logger.info("i = {}", i++);
>             TimeUnit.MILLISECONDS.sleep(100);
>         }
>
>     }
> }
>
> Gradle build of first project:
> apply plugin: 'java'
>
> sourceCompatibility = '1.8'
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
>
> jar {
>  from {
>         (configurations.runtime).collect {
>             it.isDirectory() ? it : zipTree(it)
>         }
>     }
>     manifest {
>         attributes 'Main-Class': 'com.slh.outputter'
>     }
> }
>
> if (!hasProperty('mainClass')) {
>     ext.mainClass = 'com.slh.outputter'
> }
>
> repositories {
>     mavenCentral()
> }
>
> dependencies {
>     compile "ch.qos.logback:logback-classic:1.1.3"
>     compile "ch.qos.logback:logback-core:1.1.3"
>     compile "org.slf4j:slf4j-api:1.7.12"
>     testCompile group: 'junit', name: 'junit', version: '4.10'
> }
>
>
> Second project:
> package com.slh;
> import java.io.IOException;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class outputtercaller {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(outputtercaller.class);
>
>     public static void main(String[] args) throws IOException,
> InterruptedException {
>         Process ps;
>         logger.info("Running outputter.jar. See the log file");
>         ps = Runtime.getRuntime().exec("java -jar outputter.jar ");
>         ps.waitFor();
>         logger.info("finished running outputter.jar");
>     }
> }
>
> Second project's gradle build file:
> apply plugin: 'java'
>
> sourceCompatibility = '1.8'
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
>
> jar {
>  from {
>         (configurations.runtime).collect {
>             it.isDirectory() ? it : zipTree(it)
>         }
>     }
>     manifest {
>         attributes 'Main-Class': 'com.slh.outputtercaller'
>     }
> }
>
> if (!hasProperty('mainClass')) {
>     ext.mainClass = 'com.slh.outputtercaller'
> }
>
> repositories {
>     mavenCentral()
> }
>
> dependencies {
>   compile "ch.qos.logback:logback-classic:1.1.3"
>   compile "ch.qos.logback:logback-core:1.1.3"
>   compile "org.slf4j:slf4j-api:1.7.12"
>
>     testCompile group: 'junit', name: 'junit', version: '4.10'
> }
>
>
> Both programs have their own logback.xml files which look like this:
>
> <configuration>
>   <!-- always a good activate OnConsoleStatusListener -->
>   <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"
> />
>
>   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>     <!-- encoders are assigned the type
>          ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
>     <encoder>
>       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
> %msg%n</pattern>
>     </encoder>
>   </appender>
>
>   <appender name="FILE"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
>     <file>outputter.log</file>
>     <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>       <fileNamePattern>crystal.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
>       <maxHistory>10000</maxHistory>
>     </rollingPolicy>
>
>     <encoder>
>       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
> %msg%n</pattern>
>     </encoder>
>   </appender>
>
>  <logger name="com.slh" level="INFO"/>
>
>
>   <root level="debug">
>       <appender-ref ref="FILE" />
>       <appender-ref ref="STDOUT" />
>   </root>
>
> </configuration>
>
>
>
>
> On Mon, Jun 27, 2016 at 10:32 AM, Navin Ipe
> <[hidden email]> wrote:
>>
>> Hi,
>>
>> I'm using...
>>
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>> static Logger logger = LoggerFactory.getLogger(MyClass.class);
>> Process ps;
>> ps = Runtime.getRuntime().exec("java -jar myclass.jar");
>> ps.waitFor();
>>
>> MyClass is part of a Spring Boot project which uses these dependencies:
>> dependencies {
>>   compile "ch.qos.logback:logback-classic:1.1.3"
>>   compile "ch.qos.logback:logback-core:1.1.3"
>>   compile "org.slf4j:slf4j-api:1.7.12"
>>
>> Problem is...
>> myclass.jar runs fine for a while and I can see the outputs of the logger
>> in myclass.log, but after a few hundred lines, there are no more log outputs
>> visible. Moreover, the program itself doesn't seem to function anymore (the
>> program is supposed to be writing to MySQL) but the program does not quit
>> either. It just appears to hang. I left it for 14 hours like that, and
>> nothing proceeded. There's no while loop after ps.waitFor(), and the code is
>> itself not in an infinite loop. As long as the logs are written to the file,
>> the program also writes to MySQL.
>>
>> On the other hand, if I switch off logging, the program works fine from
>> start to end, writes to MySQL and completes running in 6 hours and exits
>> fine.
>>
>> I'm considering writing a small sample program to test it out separately,
>> but considered asking here in case this is a known issue.
>>
>>
>> --
>> Regards,
>> Navin
>
>
>
>
> --
> Regards,
> Navin
>
> _______________________________________________
> slf4j-user mailing list
> [hidden email]
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Navin Ipe
Bingo. Disabling the console appender made it work.
I want to understand this properly though. Even if the logs get accumulated in the output stream, why would the program hang? I'd have assumed the OutputStream is on a separate thread.
Is there any way to flush it either during runtime or to place a configuration parameter that forces auto-flushes? Already googled, but didn't find anything that worked.

On Mon, Jun 27, 2016 at 4:59 PM, Chetan Mehrotra <[hidden email]> wrote:
What happens if you try to disable the ConsoleAppender for outputter.
Probably logs are getting accumulated in the output stream. But the
java code is not draining it out so once it reaches the bugger limit
it gets blocked.
Chetan Mehrotra


On Mon, Jun 27, 2016 at 4:22 PM, Navin Ipe
<[hidden email]> wrote:
> Confirmed. There is a problem. Even without Spring Boot. Just using logback
> and slf4j. A very very simple program. It outputs upto i=1146 and then the
> program hangs.
> Why does this happen?
>
> You could try it yourself. The program is given below. You'll be able to
> build and run the project without gradle too. Just use your favourite build
> tool like Ant or Maven.
>
> First project:
> package com.slh;
> import java.util.concurrent.TimeUnit;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class outputter {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(outputter.class);
>
>     public static void main(String[] args) throws InterruptedException,
> SQLException {
>         logger.info("Outputter started");
>         Integer i = 0;
>
>         while(true) {
>             logger.info("i = {}", i++);
>             TimeUnit.MILLISECONDS.sleep(100);
>         }
>
>     }
> }
>
> Gradle build of first project:
> apply plugin: 'java'
>
> sourceCompatibility = '1.8'
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
>
> jar {
>  from {
>         (configurations.runtime).collect {
>             it.isDirectory() ? it : zipTree(it)
>         }
>     }
>     manifest {
>         attributes 'Main-Class': 'com.slh.outputter'
>     }
> }
>
> if (!hasProperty('mainClass')) {
>     ext.mainClass = 'com.slh.outputter'
> }
>
> repositories {
>     mavenCentral()
> }
>
> dependencies {
>     compile "ch.qos.logback:logback-classic:1.1.3"
>     compile "ch.qos.logback:logback-core:1.1.3"
>     compile "org.slf4j:slf4j-api:1.7.12"
>     testCompile group: 'junit', name: 'junit', version: '4.10'
> }
>
>
> Second project:
> package com.slh;
> import java.io.IOException;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class outputtercaller {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(outputtercaller.class);
>
>     public static void main(String[] args) throws IOException,
> InterruptedException {
>         Process ps;
>         logger.info("Running outputter.jar. See the log file");
>         ps = Runtime.getRuntime().exec("java -jar outputter.jar ");
>         ps.waitFor();
>         logger.info("finished running outputter.jar");
>     }
> }
>
> Second project's gradle build file:
> apply plugin: 'java'
>
> sourceCompatibility = '1.8'
> [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
>
> jar {
>  from {
>         (configurations.runtime).collect {
>             it.isDirectory() ? it : zipTree(it)
>         }
>     }
>     manifest {
>         attributes 'Main-Class': 'com.slh.outputtercaller'
>     }
> }
>
> if (!hasProperty('mainClass')) {
>     ext.mainClass = 'com.slh.outputtercaller'
> }
>
> repositories {
>     mavenCentral()
> }
>
> dependencies {
>   compile "ch.qos.logback:logback-classic:1.1.3"
>   compile "ch.qos.logback:logback-core:1.1.3"
>   compile "org.slf4j:slf4j-api:1.7.12"
>
>     testCompile group: 'junit', name: 'junit', version: '4.10'
> }
>
>
> Both programs have their own logback.xml files which look like this:
>
> <configuration>
>   <!-- always a good activate OnConsoleStatusListener -->
>   <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"
> />
>
>   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>     <!-- encoders are assigned the type
>          ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
>     <encoder>
>       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
> %msg%n</pattern>
>     </encoder>
>   </appender>
>
>   <appender name="FILE"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
>     <file>outputter.log</file>
>     <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>       <fileNamePattern>crystal.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
>       <maxHistory>10000</maxHistory>
>     </rollingPolicy>
>
>     <encoder>
>       <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
> %msg%n</pattern>
>     </encoder>
>   </appender>
>
>  <logger name="com.slh" level="INFO"/>
>
>
>   <root level="debug">
>       <appender-ref ref="FILE" />
>       <appender-ref ref="STDOUT" />
>   </root>
>
> </configuration>
>
>
>
>
> On Mon, Jun 27, 2016 at 10:32 AM, Navin Ipe
> <[hidden email]> wrote:
>>
>> Hi,
>>
>> I'm using...
>>
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>> static Logger logger = LoggerFactory.getLogger(MyClass.class);
>> Process ps;
>> ps = Runtime.getRuntime().exec("java -jar myclass.jar");
>> ps.waitFor();
>>
>> MyClass is part of a Spring Boot project which uses these dependencies:
>> dependencies {
>>   compile "ch.qos.logback:logback-classic:1.1.3"
>>   compile "ch.qos.logback:logback-core:1.1.3"
>>   compile "org.slf4j:slf4j-api:1.7.12"
>>
>> Problem is...
>> myclass.jar runs fine for a while and I can see the outputs of the logger
>> in myclass.log, but after a few hundred lines, there are no more log outputs
>> visible. Moreover, the program itself doesn't seem to function anymore (the
>> program is supposed to be writing to MySQL) but the program does not quit
>> either. It just appears to hang. I left it for 14 hours like that, and
>> nothing proceeded. There's no while loop after ps.waitFor(), and the code is
>> itself not in an infinite loop. As long as the logs are written to the file,
>> the program also writes to MySQL.
>>
>> On the other hand, if I switch off logging, the program works fine from
>> start to end, writes to MySQL and completes running in 6 hours and exits
>> fine.
>>
>> I'm considering writing a small sample program to test it out separately,
>> but considered asking here in case this is a known issue.
>>
>>
>> --
>> Regards,
>> Navin
>
>
>
>
> --
> Regards,
> Navin
>
> _______________________________________________
> slf4j-user mailing list
> [hidden email]
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user



--
Regards,
Navin

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Chetan Mehrotra
On Tue, Jun 28, 2016 at 11:15 AM, Navin Ipe
<[hidden email]> wrote:
> Even if the logs get accumulated in the output stream, why would the program
> hang? I'd have assumed the OutputStream is on a separate thread.

That needs to be done by the caller i.e. program which is executing
the process. Have a look at [1]. Note it has nothing specific to
slf4j, it would happen with any code flow which writes to stdout

----
By default, the created subprocess does not have its own terminal or
console. All its standard I/O (i.e. stdin, stdout, stderr) operations
will be redirected to the parent process, where they can be accessed
via the streams obtained using the methods
getOutputStream(),getInputStream(), and getErrorStream(). The parent
process uses these streams to feed input to and get output from the
subprocess. Because some native platforms only provide limited buffer
size for standard input and output streams, **failure to promptly
write the input stream or read the output stream of the subprocess may
cause the subprocess to block, or even deadlock.**
----

For an example see PumpStreamHandler [2] from commons-exec which does
this properly.

Chetan Mehrotra
[1] https://docs.oracle.com/javase/7/docs/api/java/lang/Process.html
[2] https://github.com/apache/commons-exec/blob/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

Navin Ipe
Thank you.

On Tue, Jun 28, 2016 at 11:44 AM, Chetan Mehrotra <[hidden email]> wrote:
On Tue, Jun 28, 2016 at 11:15 AM, Navin Ipe
<[hidden email]> wrote:
> Even if the logs get accumulated in the output stream, why would the program
> hang? I'd have assumed the OutputStream is on a separate thread.

That needs to be done by the caller i.e. program which is executing
the process. Have a look at [1]. Note it has nothing specific to
slf4j, it would happen with any code flow which writes to stdout

----
By default, the created subprocess does not have its own terminal or
console. All its standard I/O (i.e. stdin, stdout, stderr) operations
will be redirected to the parent process, where they can be accessed
via the streams obtained using the methods
getOutputStream(),getInputStream(), and getErrorStream(). The parent
process uses these streams to feed input to and get output from the
subprocess. Because some native platforms only provide limited buffer
size for standard input and output streams, **failure to promptly
write the input stream or read the output stream of the subprocess may
cause the subprocess to block, or even deadlock.**
----

For an example see PumpStreamHandler [2] from commons-exec which does
this properly.

Chetan Mehrotra
[1] https://docs.oracle.com/javase/7/docs/api/java/lang/Process.html
[2] https://github.com/apache/commons-exec/blob/trunk/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user



--
Regards,
Navin

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Does slf4j have a conflict with Spring Boot or Java Process Runtime, because it stops logging after a while

niels
In reply to this post by Navin Ipe
I would guess you use the consolelogger and after a while the buffer is full ps hangs.Without the information about the appender it's hard to analyse. 
Perhaps it would be better to call the java-program directly and not start a java-process to start a java-process.
Niels

2016-06-27 7:02 GMT+02:00 Navin Ipe <[hidden email]>:
Hi,

I'm using...

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
static Logger logger = LoggerFactory.getLogger(MyClass.class);
Process ps;
ps = Runtime.getRuntime().exec("java -jar myclass.jar");
ps.waitFor();


MyClass is part of a Spring Boot project which uses these dependencies:
dependencies {
  compile "ch.qos.logback:logback-classic:1.1.3"
  compile "ch.qos.logback:logback-core:1.1.3"
  compile "org.slf4j:slf4j-api:1.7.12"


Problem is...
myclass.jar runs fine for a while and I can see the outputs of the logger in myclass.log, but after a few hundred lines, there are no more log outputs visible. Moreover, the program itself doesn't seem to function anymore (the program is supposed to be writing to MySQL) but the program does not quit either. It just appears to hang. I left it for 14 hours like that, and nothing proceeded. There's no while loop after ps.waitFor(), and the code is itself not in an infinite loop. As long as the logs are written to the file, the program also writes to MySQL.

On the other hand, if I switch off logging, the program works fine from start to end, writes to MySQL and completes running in 6 hours and exits fine.

I'm considering writing a small sample program to test it out separately, but considered asking here in case this is a known issue.


--
Regards,
Navin

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Loading...