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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:46:29+00:00 2026-06-08T07:46:29+00:00

I have coded a pretty simple Java 2D game with only two threads –

  • 0

I have coded a pretty simple Java 2D game with only two threads – a music player and the game. I noticed when I kick on the game that my CPU utilization shoots up from the 20% range to the 70% range. A lot of the processing I want in the game isn’t even implemented yet!

  1. Is this a concern? – shouldn’t a simple game not hog so much CPU?

  2. If it is a concern; what are GENERAL coding practices or design patterns to avoid a huge leap in utilization (other than no multithreading)?

  • 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-06-08T07:46:31+00:00Added an answer on June 8, 2026 at 7:46 am

    If it is a concern; what are GENERAL coding practices or design patterns to avoid a huge leap in utilization (other than no multithreading)?

    Most game engines have a game logic update function which is called 60 times a second, and a drawing function which is called as often as the computer has resources to (but not more than the logic updates).

    The general coding practice here is that you don’t want to update the game more than you need to. Try putting a counter in your main loop and seeing how many times in 10 seconds it is called? If you are running more than 60 updates a second, there is no need for this CPU burden!

    It looks like you are not using a game engine that gives you this, so you could hack together a solution: have your main while loop find the current time (Java’s DateTime gives you millisecond precision, whcih is good enough), and then compare it to the update time on the last loop. If not enough time has passed, use Thread.sleep() to take the burden off the CPU while your game waits to run its next iteration!

    One last comment:

    (other than no multithreading)

    While having the CPU switch threads causes a little bit of overhead, I don’t think using many well-written threads should make the CPU work harder (I’m assuming the sum of the work is the same as with less threads). In fact, if your machine is multi-core it would let your game work faster if there was a part where it needed the CPU (assuming your threads are concurrent instead of blocking one another)!

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

Sidebar

Related Questions

I have some pretty simple Java code in which I'm starting another process and
First I would like to say that I have only worked with java for
I have a simple Java app that inserts records into a table A, linking
I'm doing some relatively simple I/O in Java. I have a .txt files that
I have a problem with WCF. My testing code is pretty simple. I call
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have a pretty typical bookmarklet code that's working perfectly for me in all
I have written some code in java that will guess a number based on
Here is my code, pretty simple really. Its not homework, I'm teaching myself java
I'm using Eclipse, and I have a pretty simple project, I'll save you the

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.