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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:55:19+00:00 2026-06-13T11:55:19+00:00

In my application, I want to increase CPU usage of application to desired value

  • 0

In my application, I want to increase CPU usage of application to desired value of user and make it steady till user intrest.
I am calculating total CPU usage using following method using top command.

sample code :

private long getCpuUsageStatistic() {
           usage =0;
          String tempString = executeTop(); // executeTop is method where I fire top command.


           tempString = tempString.replaceAll(",", "");
           tempString = tempString.replaceAll("User", "");
           tempString = tempString.replaceAll("System", "");
           tempString = tempString.replaceAll("IOW", "");
           tempString = tempString.replaceAll("IRQ", "");
           tempString = tempString.replaceAll("%", "");
           for (int i = 0; i < 10; i++) {
                tempString = tempString.replaceAll("  ", " ");
           }
           tempString  = tempString.replaceAll("  ", " ");
           tempString = tempString.trim();
           String[] myString = tempString.split(" ");
           int[] cpuUsageAsInt = new int[myString.length]; 
           for (int i = 0; i < 2; i++) {
                myString[i] = myString[i].trim();
                cpuUsageAsInt[i] = Integer.parseInt(myString[i]);
                //System.out.println("getCpuUsageStatistic-----"+cpuUsageAsInt[i]);
           }
           usage = cpuUsageAsInt[0]+cpuUsageAsInt[1];
           System.out.println("getCpuUsageStatistic-----"+usage); 
           return usage;
     }


And trying to incrase CPU usage by reducing sleeping time of running thread.

but, application COU usage is not increased.

My run method is like following::

public void run() {


           while (true) {
                try {

                     Thread.sleep(READ_INTERVAL);
                     totalUsage += cpuUpdate();
                     count++;
                     float cpuUsage = totalUsage / count;

                     if (count >= 10) {
                           if (cpuUsage >= desiredCpuUsage) {
                                System.out.println("cpu usage::%" + cpuUsage);

                                break;
                           } else {


                                System.out.println("cpu usage::%" + cpuUsage);
                         if(READ_INTERVAL / reducingFactor < 190)
                         {
                             if(cpuUsage / desiredCpuUsage< 0.2)
                             {
                                 reducingFactor = reducingFactor / 1.2;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.5)
                             {
                                 reducingFactor = reducingFactor / 1.5;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.6)
                             {
                                 reducingFactor = reducingFactor / 3.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.7)
                             {
                                 reducingFactor = reducingFactor / 4.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.75)
                             {
                                 reducingFactor = reducingFactor / 5.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.8)
                             {
                                 reducingFactor = reducingFactor / 6.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.85)
                             {
                                 reducingFactor = reducingFactor / 7.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.9)
                             {
                                 reducingFactor = reducingFactor / 9.0;
                             }
                             else if(cpuUsage / desiredCpuUsage < 0.95)
                             {
                                 reducingFactor = reducingFactor / 12.0;
                             }
                             else
                             {
                                 reducingFactor = reducingFactor / 15.0;
                             }
                         }
                         READ_INTERVAL-= reducingFactor;
                     }
                           cpuUsage=0;
                           count=0;
                           System.out.println("Read_interval" + READ_INTERVAL
                                     + "::cpu usage::%::" + cpuUsage);

                 }          



                           }


                catch (Exception e) {
                     e.printStackTrace();
                }  
           }
     }

please provide the solution and any technique to increase or decrease the usage of the cpu.
thanks in advance.

  • 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-13T11:55:20+00:00Added an answer on June 13, 2026 at 11:55 am

    I would suggest to use some Math functions in a while-loop with Thread.sleep to cap it.

    I am not sure if the Dalvik VM can be forced to accept the load or if it will optimise its runtime schedule to balance the load.

    I just know that a lot of sin/cos functions create a pretty stable load that, in theory, should be easy to scale up and down by simply adding more or less calculations.

    I just dont know how the VM handles this on a multi-core cpu, because if it suddenly moves the load off to the other core, the load on the first core drops or worse, changes all the time.

    But i think its worth a try

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

Sidebar

Related Questions

I want to test the age of a user of my Rails application using
Hi I want to increase the performance of asp.net application when multiple user access
I want to have a value that increase overtime even when the application is
In my application I want to change the src value of iframe on click
In my application i want to select the video from library by using UIImagePickerController.
I want a timepickerDialog in my application, that can increase minute by 15 and
I am making a Windows Forms application. I want the forms height to increase
My current application running on 2GB memory Normal GC cycle. I want to increase
In my application I just want to listen to the picture captured by user
in my application i have to make settings button in tabbar .so using this

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.