I have implemented a socket-based client-server architecture where the server receives requests from the client, does some computation and returns a result. For simplicity, assume that the client sends a request to the server and the server executes a task 100 times returning an array of those results.
I packaged the server as a jar file and I am firing up a new server process within the client (aiming to achieve parallel processing at some point). However, the iterative process freezes at the 80th iteration :S. When I stop the execution the server carries on and completes its task.
I also tried running the server-client using the following options:
- As separate Java applications (first the server and then the client)
- From the same Java application (starting the server first and then the client)
Both 1 & 2 work fine but the intended way halts at some point.
Do you know what might be the problem?
Update
It seems that server execution freezes when it tries to write to a file (System.err in that case)
Stack trace:
java.io.FileOutputStream.writeBytes(Native Method)
java.io.FileOutputStream.write(FileOutputStream.java:326)
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
java.io.PrintStream.write(PrintStream.java:482)
sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104)
java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185)
java.io.PrintStream.write(PrintStream.java:527)
java.io.PrintStream.print(PrintStream.java:669)
java.io.PrintStream.append(PrintStream.java:1065)
java.io.PrintStream.append(PrintStream.java:57)
java.util.Formatter$FixedString.print(Formatter.java:2595)
java.util.Formatter.format(Formatter.java:2508)
java.io.PrintStream.format(PrintStream.java:970)
java.io.PrintStream.printf(PrintStream.java:871)
Update 2
Problem: Buffer overflow on server side
Solutions:
A) Increase Eclipse output console capacity (instructions here).
B) Redirect System.out or System.err to a file.
C) As suggested by @Eashi: disable System.err/out (instructions here).
D) Another good solution by @Peter Lawrey if you use ProcessBuilder: merge System.err with System.out by
ProcessBuilder pb = new ProcessBuilder(....);
pb.redirectErrorStream(true);