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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:50:33+00:00 2026-05-13T22:50:33+00:00

Greetings I am running my webapp on Tomcat6 on Java6 on Ubuntu8.04. The main

  • 0

Greetings

I am running my webapp on Tomcat6 on Java6 on Ubuntu8.04.
The main servlet of this app opens a ServerSocket, with the following simple code:

ServerSocket serverSocket = new ServerSocket(6767);

Socket xmlSocket = serverSocket.accept();        

Of course this runs in a separate thread and with the necessary try-catch blocks.

When I start Tomcat, it immediately goes to 100% CPU load and stays there until a client connects on port 6767. For as long as the client is connected, load goes down to 0%. As soon as the client disconnects, load goes back up to 100%.

Can anybody tell me what this is about?

Thanks!

SOLUTION:

Both the answers below were very helpful. The problem did NOT actually have to do with the ServerSocket, but with a sleepless while loop in a completely different thread of the app, but also dependent on whether a client was connected or not.

I was able to identify the active threads with the JDK command “jstack” and then it was an easy thing to find the one with the runaway loop.

Thanks for the help! 🙂

  • 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-13T22:50:34+00:00Added an answer on May 13, 2026 at 10:50 pm

    As soon as the client disconnects, load goes back up to 100%.

    This is usually the case in a “while loop” without sleep() in it.
    See this thread for illustration.

    Example:

    try
    {
      while (m_flagRunUserThreadManager)
      {
        try
        {
          m_listenSocket.setSoTimeout(10000);
          Socket clientSocket = m_listenSocket.accept();
          //create a thread for client
          MyClientHandler clientHandler = new ClientHandler(clientSocket);
          clientHandler.setPriority(Thread.MIN_PRIORITY);
          clientHandler.start(); 
    
        }
        catch(SocketTimeoutException excp)
        {
          String strError = "No requests for 10 Sec.";
          //display this message    
        }
      }
    }
    catch(IOException excp)
    {
        // display the exception
    }
    

    This is because your while loop has a path through it with no sleep, specifically when your try fails.
    You need to have a sleep somewhere, so other threads/processes get a chance. Either that or don’t keep trying on a client that has alreay failed.

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

Sidebar

Related Questions

Greetings! I'd like to investigate Django but I'm running Windows XP. I've installed XMPP
Greetings! I'd like to build an apache web server, running on debian lenny. It
Greetings, The VBA code below will create an Excel QueryTable object and display it
I have successfully implemented this from android to a java httpservlet on google app
Greetings - I have a SharePoint 2010 server running with the User Profile service
Greetings folks! I'm running into a problem with WPF databinding that I hope you
Greetings, I have a few applications/websites running with LINQ to SQL and the other
Greetings. I have a .NET application running a bunch of simulations in parallel. It's
Greetings, In Jmeter's regex component, I am running into an issue when the expression
Greetings, I'm trying to develop some tests for Mason components which requires running them

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.