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
Solved

writing to outputstream

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 61
Tomcat: Unable to run tomcat service. 2 23
Adding multiple JVM environments to RedHat 6 7 45
collection output issue 9 36
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

791 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