Solved

writing to outputstream

Posted on 1998-09-07
4
607 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

729 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