Posts

Increase Heap Size in Java

Tomcat on Windows (started manually) If you run Tomcat (eg. from JIRA Standalone) on Windows, and are starting it manually by running bin\startup.bat, edit bin\setenv.bat and add the line: setenv.bat set JAVA_OPTS =-Xms256m -Xmx256m and then restart. Adjust 256 to the maximum memory you want to allocate. If bin\setenv.bat does not exist, create it.

Stopwatch in java

import org.apache.commons.lang.time. StopWatch ; StopWatch clock = new StopWatch (); clock.start(); for( int i = 0; i < 100000000; i++ ) { Math.sin( 0.34 ); } clock.stop(); System.out.println( "It took" + clock.getTime() + " milliseconds" );

Java programming best practices

Following are some performance tips in Java. We know many of them still do not use them in regular practice. Compile-Time Initialization for (int i =0; i < loop; i++) { //Looping 10M rounds String x = "Hello" + "," +" "+ "World"; } Better way is.... for (int i =0; i < loop; i++) { //Looping 10M rounds String x = new String("Hello" + "," +" "+ "World"); } ------------------------------------------------------------------------------------------------------------------- Runtime String Initialization String name = "Smith"; for (int i =0; i < loop; i++) { //Looping 1M rounds String x = "Hello"; x += ","; x += " Mr."; x += name; } Better way is.... String name = "Smith"; for (int i =0; i < loop; i++) { //Looping 1M rounds String x = (new StringBuffer()).append("Hello").append(",").append(" ").append(name).toString(...