-1

I need to do a simulation of a server on my local computer where the cpu is permanently loaded/utilized to an amount of about 80%.

Does anyone have an idea how i can manage to do that using Java?

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
user1765902
  • 281
  • 1
  • 3
  • 8
  • Use multiple threads with an endless loop? It's hard to exactly get 80% CPU usage but if you have let's say 4 hardware threads, you could try and use 3 high priority threads with an endless loop to get 75% CPU usage. – Thomas Feb 05 '14 at 12:56
  • Does it need be a piece of code you wrote? As http://www.jam-software.com/heavyload/ can do this for you. – BadSkillz Feb 05 '14 at 13:02

1 Answers1

1

What you need is number of CPUs threads that you let run in loops for 0.8 seconds, each second.

You can do that by using the Java threads and implementing the run() methods as while loops, checking the time constantly. every time they worked for 0.8 seconds, let them sleep for .2 seconds.

Theolodis
  • 4,977
  • 3
  • 34
  • 53
  • That raises a question for me: 80% of the actual CPU, or 80% of one core? "CPU" is not so clearly defined nowadays. – Gimby Feb 05 '14 at 15:22
  • @gimby By implementing it the way I suggested you would occupy 80% of each processing unit (core), meaning 80% of the hardware-CPU. You are right that CPU is not clearly defined. Let's just suppose that as I am speaking of multiple CPUs I was not talking of one CPU ;) – Theolodis Feb 06 '14 at 08:15