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
, , StringBuilder vs String . "" , , ( ), . , StringBuilder , String, StringBuffer, String.format(), MessageFormat...
, , , StringBuilder.
. 5%. . Spring AOP Thread.sleep() , - . Thread.sleep() , . , . , . , , , , .
" " StringBuilder . , :
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. , +. .
+
, , - , . , , .
? , , . Thread.sleep(60 * 1000); , . - , ?
Thread.sleep(60 * 1000);
, :
while(true) { //Code Thread.sleep (1000); //Wait 1 second }
, , , , , .
. StringBuilders, .
Thread.yield()
JVM Linux - Unix, nice 20.
, VirtualBox, .
, , - Thread.sleep.
Thread.sleep
, -, , ( ) . , , .
, .
wait();
notifyAll()