Solved

Faster bufferedInputStream, is it possible?

Posted on 1998-08-03
7
337 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now