Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:54:40+00:00 2026-05-14T18:54:40+00:00

We are working to reduce the latency and increase the performance of a process

  • 0

We are working to reduce the latency and increase the performance of a process written in Java that consumes data (xml strings) from a socket via the readLine() method of the BufferedReader class. The data is delimited by the end of line separater (\n), and each line can be of a variable length (6KBits – 32KBits). Our code looks like:

Socket sock = connection;
InputStream in = sock.getInputStream();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(in));
...
do 
{
   String input = inputReader.readLine();
   // Executor call to parse the input thread in a seperate thread
}while(true)

So I have a couple of questions:

  • Will the inputReader.readLine() method return as soon as it hits the \n character or will it wait till the buffer is full?
  • Is there a faster of picking up data
    from the socket than using a
    BufferedReader?
  • What happens when the size of the input string is smaller than the size of the Socket’s receive buffer?
  • What happens when the size of the
    input string is bigger than the size
    of the Socket’s receive buffer?

I am getting to grips (slowly) with Java’s IO libraries, so any pointers are much appreciated.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:54:41+00:00Added an answer on May 14, 2026 at 6:54 pm

    Will the inputReader.readLine() method return as soon as it hits the \n character or will it wait till the buffer is full?

    • It will return as soon as it gets a newline.

    Is there a faster of picking up data from the socket than using a BufferedReader?

    • BufferedReader entails some copying of the data. You could try the NIO apis, which can avoid copying, but you might want to profile before spending any time on this to see if it really is the I/O that is the bottleneck. A simpler quick fix is to add a BufferedInputStream around the socket, so that each read is not hitting the socket (It’s not clear if InputStreamReader does any buffering itself.) e.g.

      new BufferedReader(new InputStreamReader(new BufferedInputStream(in)))

    What happens when the size of the input string is smaller than the size of the Socket’s receive buffer?

    • The BufferedReader will fetch all the data availalbe. It will then scan this data to look for the newline. The result is that subsequent reads may already have the data in the BufferedReader.

    What happens when the size of the input string is bigger than the size of the Socket’s receive buffer?

    • The bufferedReader will read what is in the recieve buffer, and as there is no newline or the end of stream is reached, it will continue to read data from the socket until it finds EOF or a newline. Subsequent reads may block until more data becomes available.

    To sum up, BufferedReader blocks only when absolutely necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code is working perfectly to reduce the size of a UITextView when the
I am working on a .NET application to reduce image file sizes using ImageMagick
I'd like to reduce actual database hits when working in django so I've created
I'm working on a Hadoop streaming workflow for Amazon Elastic Map Reduce and it
I'm using TPTP to profile some slow running Java code an I came across
is using empty working set or forcing GC collects a recommended practices in trying
I am about to dive into a rules oriented project (using ILOGs Rules for
So in my local app, everything is fine. Both are running Ruby 1.8.7, and
I've been trying to compare the memory footprint between a VB6 application and .Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.