Solved

writing to outputstream

Posted on 1998-09-07
4
606 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 110
check java version using powershell 13 307
hibernate example for saving data 19 80
American Express @Work site and Java 4 69
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

696 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