Solved

Faster bufferedInputStream, is it possible?

Posted on 1998-08-03
7
357 Views
Last Modified: 2010-04-16
Hello.

I have a problem with bufferedinputstream, is there a way to speed it up.
So i can read faster from the bufferedinputstream?

Pierre Andersson
0
Comment
Question by:pierre_andersson
[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
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1230724
What seems to be the problem with the bufferedinputstream's speed? Can you attach a code that shows the problem?
0
 

Author Comment

by:pierre_andersson
ID: 1230725
The problem is as follow:

I have a buffer with 200000 bytes and a bufferedinputstream connected to a server over a socket. When the server is sending really fast(1 String/ 1/2 second) the buffer(byte[200000]) is filled with strings and the time for the string to be shown in the client window is incresing.

Pierre Andersson.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230726
Pierre, could it be that you are displaying all the data in the buffer each time you display? That would explain the fact that the display time is increasing. Why don't you work with smaller buffers? It would be much more efficient.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:pierre_andersson
ID: 1230727
Thanks for your answer!!!

The problem is that i don't really know how big the buffer must be, because the server must serve 4000 clients and broadcast all the message to all the clients each time the server is receiving a message. I don't think that alla the clients will send a message at the same time but i want the server and client to be as fastest they can. Do you know what size the buffer should be.

Thanks for your help.

Pierre Andersson.
0
 
LVL 6

Accepted Solution

by:
gadio earned 100 total points
ID: 1230728
Pierre, when you read and write to sockets you are I/O bound, that is, the cpu is idle most of the time waiting for the communication to happen. I suggest that you try a different approach. If your messages are delimited by newline, try to use

// the input stream from the client socket is inpstr
BufferedReader br = BufferedReader(new InputStreamReader( inpstr ) );
while( /*condition*/ ) {
   String msg = br.readLine();
   if( /* msg is relevant to me */ ) {
      // Handle message
   }
}

If on the other hand, the message is delimited by some other characters, use the StreamTokenizer to break the stream to messages.

0
 

Author Comment

by:pierre_andersson
ID: 1230729
I am using $ to delimite the strings and StringTokenzier, is StringTokenizer ok, or should i use StreamTokenizer.

Pierre Andersson
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230730
Use StreamTokenizer, mark all the characters that can be a part of a message as normal (including spaces), and the $ as whiteSpaceChars.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 video teaches viewers about errors in exception handling.

726 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