Solved

Faster bufferedInputStream, is it possible?

Posted on 1998-08-03
7
334 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
parentbit challenge 3 52
for i loop in grovy 1 32
Starting to learn JAVA, 7 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

760 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

20 Experts available now in Live!

Get 1:1 Help Now