<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LoadRunner TnT &#187; Coding</title>
	<atom:link href="http://www.loadrunnertnt.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.loadrunnertnt.com</link>
	<description>Performance Testing, LoadRunner Tips &#38; Tricks</description>
	<lastBuildDate>Mon, 08 Mar 2010 07:57:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Achieving High Performance Application in Java Coding! – Part 3</title>
		<link>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-3/</link>
		<comments>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-3/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:22:07 +0000</pubDate>
		<dc:creator>TnT Admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.loadrunnertnt.com/?p=694</guid>
		<description><![CDATA[Code with performance in mind!  Follow these next 7 good coding practises that can be easily achieved for high performance!

Beware of “Thread.run()” versus the real intend of “Thread.start()” – We may unknowingly code the thread as “run()”.  This will cause the thread to run sequentially instead of concurrently. Beware of this!  Use “Thread.start()” to allow [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.loadrunnertnt.com/wp-content/uploads/2010/02/web_coding_collage-150x150.jpg"><img class="size-full wp-image-698 alignright" title="web_coding_collage-150x150" src="http://www.loadrunnertnt.com/wp-content/uploads/2010/02/web_coding_collage-150x150.jpg" alt="" width="81" height="81" /></a>Code with performance in mind!  Follow these next 7 good coding practises that can be easily achieved for high performance!<span id="more-694"></span></p>
<ul>
<li><strong>Beware of “Thread.run()” versus the real intend of “Thread.start()”</strong> – We may unknowingly code the thread as “run()”.  This will cause the thread to run sequentially instead of concurrently. Beware of this!  Use “Thread.start()” to allow the thread to run concurrently.</li>
<li><strong>Use “String.length ()  == 0” instead of “String.equals(“”)”</strong> – Both constructs do the same thing of comparing if any characters exists for the string. However, the first construct, “String.length() == 0” is more efficient than the latter one.</li>
<li><strong>Avoid calling “String.toCharArray()”</strong> – “toCharArray()” method is inefficient as the method reallocates the entire array stored in the string.  However, sometimes this is necessary.  Therefore, as a rule, avoid using “toCharArray()” method if possible.  If not possible, do use it with care.</li>
<li><strong>Place “try/catch/finally” block outside loop &#8211; </strong>Placing &#8220;try/catch/finally&#8221; blocks inside loops can slow down the execution of code. Do take note that moving the &#8220;try/catch/finally&#8221; block outside the loop can change program behaviour. An exception that has the “try/catch/finally” block outside the loop will terminate early.  On the other hand, the &#8220;try/catch/finally&#8221; block inside the loop may cause the program to continue iterating over the loop even after an exception has occurred.</li>
<li><strong>Use “StringBuffer.Append ()” instead of “+=” operators for concatenating strings </strong>– “Append()” has better improvement over “+=” operators and its recommended to use it instead of “+=” operators for concatenating strings.</li>
<li><strong>Do not use “StringBuffer” as constants </strong>– Dynamically resizable strings are unnecessary for constant strings (as they do not change).  Instead, use “String” for non-modifiable string constants.</li>
<li><strong>Do not open or close JDBC connections in loops </strong>– It is inefficient to open and close a connection in loop.  Instead, the connection should be opened before the loop and closed after the loop to avoid redundant calls make to the database.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Achieving High Performance Application in Java Coding! – Part 2</title>
		<link>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-2/</link>
		<comments>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-2/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 07:25:01 +0000</pubDate>
		<dc:creator>TnT Admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[finalize]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.loadrunnertnt.com/?p=666</guid>
		<description><![CDATA[Following our high performance application in java coding:

Handle the appropriate exceptions (checked); do not leave it to the unchecked exceptions – When an exception is thrown, the runtime system will exhaustively search all the methods on the call stack for the appropriate exception handler.  This is expensive and thus we want to minimize the search [...]]]></description>
			<content:encoded><![CDATA[<p>Following our <a href="../coding/achieving-high-performance-application-in-java-coding/">high performance application in java coding</a>:<a href="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage-150x1502.jpg"><img class="alignright size-full wp-image-702" title="web_coding_collage-150x150" src="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage-150x1502.jpg" alt="" width="71" height="71" /></a><span id="more-666"></span></p>
<ul>
<li><strong>Handle the appropriate exceptions (checked); do not leave it to the unchecked exceptions</strong> – When an exception is thrown, the runtime system will exhaustively search all the methods on the call stack for the appropriate exception handler.  This is expensive and thus we want to minimize the search in the call stack in finding the appropriate exception handler to improve performance which can be achieved by throwing and catching the appropriate exceptions (checked exceptions).  Do not leave exception handling as an after-thought or code-as-you-go during development.</li>
<li><strong>Do not incorporate exception handling as control flow</strong> – As mentioned earlier, exceptions are expensive and should only be used for abnormality (planned and unplanned).  An if-then-else construct will perform better without the exception handling as there is no need to transfer control to locate the appropriate exception handling.   As such, review the codes and remove any throw statements from the coding that are used in an if-then-else construct.</li>
<li><strong>Avoid and remove the use of Reflection API in the codes</strong> – Reflection involves types that are dynamically resolved, which restricts optimization in certain JVMs.  Consequently, reflective operations have slower performance than non-reflective counterparts.  Therefore, unless there is a dire need for reflection to be used in the java program, it is best to leave it out if you need a high performance program.</li>
<li><strong>Let the system decide the garbage collection</strong> – If possible, remove any attempt to call system.gc(). system.gc() triggers a full collection , which includes tracing all live objects in the heap and sweeping and compacting the old generation. This can be a lot of work. In general, it is better to let the system decide when it needs to collect the heap, and whether or not to do a full collection.  Note: system.gc() merely signals (marks) the java program to do garbage collection, but it will not be an immediate garbage collection taking place.</li>
<li><strong>Reduce memory by avoiding the use of finalizers </strong>– An object is in the <em>finalized</em> state if it is still unreachable after running the finalize method, if any, has been run.  The finalized object is then awaiting deallocation and deallocation will not take place until the finalizer is run which is dependent on the VM.  The use of finalizer will extend the lifetime of the <em>finalized</em> object and it can be counter-intuitive when no deallocation takes place and when you intended to have the object being short-lived.   In order to avoid these short-lived objects being extended during the lifetime of the heap memory, it is best to consider the use of finalizers or free the resources explicitly.   (Source: <a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html">Appendix A, The Truth About Garbage Collection</a> and <a href="http://www.ibm.com/developerworks/library/j-jtp01274.html">Java theory and practice: Garbage Collection and Performance</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Achieving High Performance Application in Java Coding!</title>
		<link>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/</link>
		<comments>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 07:20:14 +0000</pubDate>
		<dc:creator>TnT Admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[substring]]></category>

		<guid isPermaLink="false">http://www.loadrunnertnt.com/?p=620</guid>
		<description><![CDATA[High performance web sites and applications can start from the design coding level.  Most of the time, performance tuning we view comes at the later stage of the development life cycle, in particular at the deployment stage.  What can we do by deployment stage?  We can only tune start up parameters, add more hardware, or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage.jpg"><img class="alignleft size-thumbnail wp-image-633" title="web_coding_collage" src="http://www.loadrunnertnt.com/wp-content/uploads/2010/01/web_coding_collage-150x150.jpg" alt="" width="86" height="86" /></a>High performance web sites and applications can start from the design coding level.  Most of the time, performance tuning we view comes at the later stage of the development life cycle, in particular at the deployment stage.  What can we do by deployment stage?  We can only tune start up parameters, add more hardware, or add more network components in the architecture.  But what if the problem is in the JVM where you diagnose it to be poor application performance due to coding?  Changing codes at this stage will be more expensive and difficult unlike when you are in the development stage!<span id="more-620"></span></p>
<p>How can we build a high performance web site through coding then?  Here are some basic tips you should note during development which should not be a big hassle for you to make changes anytime!<strong> </strong></p>
<p><strong>1. Remove any unused      variables – </strong>The first thing and most simple thing you can do is to avoid      creating unused variables.  Use      static code analysers and look for variables that are initialized but not      used.  Sometimes, in the midst of      development, we leave out variables that aren’t used anymore and this can      be removed to converse memory.<strong></strong></p>
<p><strong>2. Free all resources – </strong>All created resources      and variables should be released once they are not used.  This helps converse memory.  This will help optimize the memory usage      and thus reduce the need for garbage collection cycle to take place.  Resources such as database connections      and files are simple examples that you should close and release the      resources.<strong></strong></p>
<p><strong>3. Free all resources in      the ‘finally’ block – </strong>Similar to [2], we want to free all      resources.  However, this is catered      to “unhappy” flow of the program code.       Free all resources that are used when exception arises if applicable.<strong></strong></p>
<p><strong>4. Avoid calling methods in loops – </strong>This can be circumvented when the compiler optimizes the code.  However, if it doesn’t the loop condition will be calculated for each iteration during the loop</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// bad practise</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MethodInLoop <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">void</span> method <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</span></a> vector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> vector.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">// do something</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// good practise</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MethodOutOfLoop <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">void</span> method <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</span></a> vector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> vector.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">// do something</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><strong>5. Avoid methods that may      cause memory leaks – </strong>Methods such as split(java.lang.String),      split(java.lang.String, int), substring(int), substring(int,int),      nextElement(), nextToken(), nextToken(java.lang.String), group() and      group(int) are candidates of memory leak.       There are quite a fair bit of search results on the methods that      causes memory leaks.  You can refer      to <a href="http://eyalsch.wordpress.com/2009/10/27/stringleaks/">“Strings      and Memory Leaks”</a> from The Java Explorer for some information.  Avoid such methods whenever      possible.  If not, do use it with      care.</p>
<p>More to come on coding for high performance applications!  Share with us on your performance coding tips here too! <img src='http://www.loadrunnertnt.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.loadrunnertnt.com/coding/achieving-high-performance-application-in-java-coding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
