Java reduces CPU usage

Greets-

We have a few crazy people at work who like to use

while(true) { //Code } 

in their code. As you can imagine, this maximizes the processor. Does anyone know of ways to reduce CPU utilization so that other people can also use the server.

The code itself simply constantly checks the Internet for updates on sites. Therefore, I would suggest that a small sleep method will significantly reduce CPU usage.

Also, all manipulations are performed in String (Java) objects, does anyone know how much StringBuilders will reduce overhead?

Thanks for any pointers

+5
source share
9 answers

, , StringBuilder vs String . "" , , ( ), . , StringBuilder , String, StringBuffer, String.format(), MessageFormat...

, , , StringBuilder.

. 5%. . Spring AOP Thread.sleep() , - . Thread.sleep() , . , . , . , , , , .

+6

" " StringBuilder . , :

String s = s1 + ":" + s2 + ":" + s3;

:

StringBuilder sb = new StringBuilder(s1);
sb.append(":");
sb.append(s2);
sb.append(":");
sb.append(s3);
String s = sb.toString();

, . , Java StringBuilder. , +. .

, , - , . , , .

+7

? , , . Thread.sleep(60 * 1000); , . - , ?

+4

, :

while(true) { 
  //Code 
  Thread.sleep (1000); //Wait 1 second
} 

, , , , , .

+2

. StringBuilders, .

+2

Thread.yield()
0

JVM Linux - Unix, nice 20.

, VirtualBox, .

, , - Thread.sleep.

0

, -, , ( ) . , , .

, .

0
  • ? RSS?
  • If they do, then there is no need to poll sites and connect instead to wait for updates. The current method then expects to usewait();
  • The new module then notifies the object using this method with notifyAll().
  • Admittedly, this is an extra job, but it saves a ton of bandwidth and computation.
0
source

All Articles