[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

writing to outputstream

Posted on 1998-09-07
4
Medium Priority
?
610 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 400 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

649 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