Solved

writing to outputstream

Posted on 1998-09-07
4
602 Views
Last Modified: 2008-03-17
If I perform a pw.println to an outputstream with a stringbuffer
containing lots of data it takes a too long time to do this.

sample code

PrintWriter pw = new PrintWriter(
                new BufferedOutputStream(clientSocket.getOutputStream(), 1024), false);

pw.println(adminDbConnect.processInput(inputLine));;
               
pw.flush();
0
Comment
Question by:felgen
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1223754
It seems that under 1.0.2 print() is really slow

Michel
0
 

Author Comment

by:felgen
ID: 1223755
print() or println()?
But I'm using 1.1.4!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1223756
Then I dunno - sorry.

Michel

PS: print or println - wouldn't they both be slow if one was???
0
 
LVL 3

Accepted Solution

by:
mjenkins earned 200 total points
ID: 1223757
Are you sure that it is the println()? Did you try to decouple the adminDbConnect.processInput(inputLine) call from the printing? JDBC calls can be very slow depending upon the driver and database used.

Also, if you have a lot of network traffic on your system, the problem may be the response time for the socket. Try something like this to isolate the problem:

FileOutputStream f = new FileOutputStream("TEST.TMP");
BufferedOutputStream bs = new BufferedOutputStream( f, 1024);
PrintWriter pw = new PrintWriter( bs, true );
System.out.println("Getting string: " );
String s = adminDbConnect.processInput(inputLine);
System.out.println( "Done!" );
System.out.println("Writing string: " );
pw.println(s);
System.out.println( "Done!" );

By separating all of the steps, you will be able to better tell where your bottle neck is. Notice that I've traded the socket output for a local file to eliminate the network as an issue. If runnin this is fine as-is, you've most likely got network contention. Otherwise, you  should be able to see if it is the "input" or "output" that is the source of your troubles.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now