This week's book giveaway is in the Testing forum. We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line! See this thread for details.
I am using string concatenation in a while loop to create a really big string. Could this take the CPU load to 100% or should I look for somethig else for answers to the CPU load problem ?
If by "concatenation" you mean either str += someOtherStr or the explicit use of the concatenate() method, then, yeah, that could be a problem for large strings in a tight loop.
However, rather than guessing at where the problem might be, you're better off using a profiler to measure it. JProbe, JProfiler, OptimizeIt, and AppPerfect all have either limited time or limited functionality demo versions, and the JDK comes with jvisualvm.
Could this take the CPU load to 100% or should I look for somethig else for answers to the CPU load problem ?
If it stays at 100% you are looking at an infinite loop instead of a string concat inefficiency. Yes concatenation is quite inefficient and StringBuilders help alleviate that. Depending on what you are trying to do, there could be other ways around concatenation. If you would like to explore other options do let us know what the concatenation attempts to achieve.
Sometimes JSON objects are quite big.
A different approach would be to generate an XML directly at the database level and just send it to the client. The CPU doesn't go to 100%, it goes to something like 70% and there are a lot of requests to the webserver.
Heroic work plunger man. Please allow me to introduce you to this tiny ad: