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 6084889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:35+00:00 2026-05-23T11:34:35+00:00

Good evening, I’m developing a java tcp server for communication between clients. At this

  • 0

Good evening,

I’m developing a java tcp server for communication between clients.

At this point i’m load testing the developed server.

This morning i got my hands on a profiler (yourkit) and started looking for problem spots in my server.

I now have 480 clients sending messages to the server every 500 msec. The server forwards every received message to 6 clients.

The server is now using about 8% of my cpu, when being on constant load.

My question is about the java functions that uses the most cpu cycles.

The java function that uses the most cpu cycles is strangly “Thread.sleep”, followed by “BufferedReader.readLine”.

Both of these functions seem to block the current thread while waiting for something (sleep waits for a few msec, readline waits for data).

Can somebody explain why these 2 functions take up that much cpu cycles? I was also wondering if there are alternative approaches that use less cpu cycles.

Kind regards,
T. Akhayo

  • 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-23T11:34:36+00:00Added an answer on May 23, 2026 at 11:34 am

    sleep() and readLine() can use a lot of cpu as they both result in system calls which can context switch. It is also possible that the timing for these methods is not accurate for this reason (it may be an over estimate)

    A way to reduce the overhead of context switches/sleep() is to have less threads and avoid needing to use sleep (e.g. use ScheduledExecutorServices), readLine() overhead can be reduced by using NIO but it is likely to add some complexity.

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

Sidebar

Related Questions

Good evening, I am developing a set of Java classes so that a container
Good evening! I'm developing a web application with asp.net C#. In this application the
Good evening, In my app that I'm currently developing, I have a class that
Good morning, afternoon, evening or night (depending on your timezone). This is just a
Good evening everyone! I am working on learning some java and I have made
Good Evening folks. This is my code: static private function removeAccentedLetters($input){ for ($i =
Good evening, I am in the process of writing a Java Servlet (Struts 2,
Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good evening, I am tired and have been fighting with this for hours. I
Good evening :-)! I have this code to use Drag & Drop method for

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.