My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Monday, January 28, 2013

Disable absolute URL access- Apache web server


you can disable accessing through absolute url and allow access only with relative url with this htaccess code 


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

Saturday, January 26, 2013

Persistence Unit not found - JPA- RESOLVED

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named

This is so annoying

I had been looking for solutions for the same. Here are the pointers for the same

Hope this helps someone.

  1. My project structure is as follows . I am using JPA2.0
  2. .
    ├── pom.xml
    └── src
        ├── main
           ├── java
              └── se
                  └── mycomp
                      ├── UserTest.java
                      └── domain
                          └── User.java
           └── resources
               ├── META-INF
                  └── persistence.xml
               └── log4j.properties
        └── test
            └── java
  3. Compare the case sensitiveness for the Persistence Unit Name.
  4. If you have JPA2.0 as a dependency, you can go ahead and remove the same
  5. Check if your provider is 
  6. <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
    Check your pom.xml if you have hibernate entity manager as a dependency.
    If needed add the hibernate annotations too . No HARM
       <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>${hibernate-core-version}</version>
        </dependency>
    
    
    Thats it, the errors are gone.

Sunday, January 6, 2013

Recursive windows commands


To do a recursive move do:
            for /r %x in (foo) do move "%x" "drive:\path\bar"
To do a recursive rename do:
            for /r %x in (*.c) do ren "%x" *.cpp

Friday, December 28, 2012

Load Properties dynamically

Use Apache Commons Configuration and you can re-load property file dynamically.

Here is the complete code snippet for you


Java Code

import java.util.Arrays;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;

public class ApacheCommonsTest {

private static final String PROPERTIES_FILE_NAME = "C:\\sampleconfig\\reloadconfig.properties"; // you can use your own folder for this

/**
* @param args
*/
public static void main(String[] args) {
ApacheCommonsTest classObj = new ApacheCommonsTest();
try {
classObj.getBackground();
classObj.getPieColors();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}

private PropertiesConfiguration getPropertyConfig()
throws ConfigurationException {
PropertiesConfiguration config = null;
config = new PropertiesConfiguration(PROPERTIES_FILE_NAME);
config.setReloadingStrategy(new FileChangedReloadingStrategy());
config.setAutoSave(true);
return config;
}

private void readProperties() throws ConfigurationException {
PropertiesConfiguration config = getPropertyConfig();
config.load(PROPERTIES_FILE_NAME);
}

private void getPieColors() throws ConfigurationException {
readProperties();
String[] piecolors = getPropertyConfig().getStringArray("colors.pie");
System.out.println("colors.pie=" + Arrays.toString(piecolors));
}

private void getBackground() throws ConfigurationException {
readProperties();
String bgcolor = getPropertyConfig().getString("colors.background");
System.out.println("bgcolor=" + bgcolor);
}
}

Sample Property file
C:\\sampleconfig\\reloadconfig.properties


colors.pie=#FF0000,#00FF00,#0000FF,#123456
colors.background=#c53478


Jar files to run this program

You can get all the jar files from findjar.com

  1. commons-configuration-1.9.jar
  2. commons-lang-2.2.jar
  3. commons-logging-1.1.1.jar
Now no more reloading with server re-start


Thursday, December 27, 2012

Enable UML shapes in Visio


  • Stencil and Template for Visio 2010

Visio 2010 represents the first noticeable improvement in usability since Visio 2000, but no enhancement in the funtionality, upon which the UML 2.2 shapes are built upon. 
Therefore, the shapes for Visio 2010 are the same as for Visio 2007; there are minor changes in the template. 

Install: If you'd like the template to appear in the "Software and Database" category when you click File/New, together with Visio's own templates, 
create in any folder a subfolder called "Software and Database", for example, "...\My Documents\My Shapes\Software and Database". 

You could choose any folder, except of the Visio program folder, i.e., don't use C:\Program Files\Microsoft Office\Office14\Visio Content\1033. 

Unzip the stencils and template into "...\My Documents\My Shapes\Software and Database" or the folder you created. 

  1. Start Visio, 
  2. click the File tab, 
  3. click Options, 
  4. click Advanced, 
  5. and then, 
  6. under General at the very bottom, 
  7. click File Locations. 
  8. Type full path of this folder without the last segment "Software and Database" into the fields "Stencils" and "Templates". 
  9. That is, type in "C:\Document and Settings\<user name>\My Documents\My Shapes\" . 

The template "UML 2.2 Template (Visio 2010)" will appear in the category "Software and Database". 

If you'd like the UML 2.2 template to appear in another category, 
such as a "UML" category, use "UML" instead of "Software and Database" in the steps above.

The stencils and template are here: UML2.2-Visio2010.zip


  • Stencil and Template for Visio 2007

This stencil for Visio 2007 contains all the same shapes as the stencil for Visio 2003, 
as Visio 2007 has almost the same functionality as Visio 2003; there were only usability improvements.  

Install: If you'd like the template to appear in the "Software and Database" category 
when you click File/New, together with Visio's own templates, 
create in any folder a subfolder called "Software and Database", 
for example, "...\My Documents\My Shapes\Software and Database". 
You could choose any folder, except of the Visio program folder, 
i.e., don't use C:\Program Files\Microsoft Office\Office11\1033. 

Unzip the stencils and template into "...\My Documents\My Shapes\Software and Database" or the folder you created. 

  1. Start Visio, 
  2. click "Tools" 
  3. and "Options". 
  4. In the "Advanced" tab, 
  5. click "File Paths..." 
  6. and type full path of this folder, 
  7. without the last element "Software and Database" into the fields "Stencils" and "Templates", 
  8. that is insert "C:\Documents and Settings\<user name>\My Documents\My Shapes\".  
  9. Restart Visio. 
  10. The template "UML 2.2 Template (Visio 2007)" will appear in the category "Software and Database". 

If you'd like the UML 2.2 template to appear in another category, 
such as a "UML" category, use "UML" instead of "Software and Database" in the steps above.

The stencils and template are here: UML2.2-Visio2007.zip.

Thursday, October 11, 2012

Tuning the compaction and thread local area (TLA) size.


a.      Compaction is used to reduce heap fragmentation, i.e., move objects to form contiguous ‘live regions’ of the heap space. Note when a full compaction is run the stopping of a concurrently running application is inevitable. We can say that compaction is one of the worst garbage collection bottlenecks. If anything is known about fragmentation and object sizes it might be beneficial to tune compaction.
b.      The compaction algorithm divides the heap into a number of equally large parts. Each of these is subject to separate compaction that can stop the world. The default is 4096 parts. When compaction is too disruptive it might help to increase the number of heap parts. When compaction fails to keep up with fragmentation it might help to decrease the number of heap parts. Note that, for strategies other than throughput the compaction areas are sized dynamically
c.       The proper tuning of compaction involves two parameters:
                                                              i.      Compaction ratio (-XX:compaction:percentage:<percentage> or -XX:compaction:internalPercentage=<percentage>,externalPercentage=<percentage>) – the percentage of the heap that the garbage collector compacts at each garbage collection. While the JVM is compacting the heap, all threads that want to access objects need to wait because the JVM is moving the objects around.
                                                            ii.      Maximum references (-XX:compaction:maxReferences:<value>) – the maximum number of references to objects in the compaction area. If the number of references exceeds this limit, the compaction is canceled. When compaction has moved objects, the references to these objects must be updated. The pause time introduced by this updating is proprotional to the number of references that have been updated
d.      steps to tune compaction are as follows:
                                                              i.      Set the compaction ratio to 1 and gradually increase the ratio until the pause time becomes too long.
                                                            ii.      If the garbage collection time is too long when the compaction ration is 1, the maximum number of references must be adjusted:
                                                          iii.      Set the maximum references to 10000 and gradually increase the references until the pause time becomes too long. To monitor compaction behavior, we can add the option -Xverbose:compaction to the command-line. If many compactions are skipped, the maximum references must be increased; if, on the other hand, the compaction pause times are too long the maximum references must be decreased.
                                                           iv.      As we are using a dynamic garbage collection that optimizes the pause time (-Xgc:pausetime), we do not need to tune the compaction manually in this case setting the -XpauseTarget is sufficient.
e.      Each thread allocates objects in a TLA that is promoted to the heap when full. The TLA size can be adjusted by using -XXtlaSize:min=<size>,preferred=<size>,wasteLimit=<size>, in which,
                                                              i.      min – sets the minimum size of a TLA.
                                                            ii.      preferred – sets the preferred size of a TLA. The system will try to get TLAs of the preferred size if possible, but accepts TLAs of minimum size as well.
                                                          iii.      wasteLimit – sets the waste limit for TLAs. This is the maximum amount of free memory that a TLA is allowed to have when a thread requires a new TLA

Wednesday, October 10, 2012

Garbage collector(s)


  1.  Garbage collector can be generational or single spaced with a parallel or a concurrent mark and a parallel sweep or a concurrent sweep:
  2. Generational garbage collection – In this case the heap is divided into two sections: an old generation and a young generation (nursery). Initially objects are allocated in the nursery and when it is full, live objects are promoted to the old generation. For this operation the collector has to stop the Java threads.
  3. Single-spaced garbage collection – All objects live in a single space on the heap, regardless of their age.
  4. Concurrent mark and sweep algorithm – The concurrent garbage collection algorithm does its marking and sweeping concurrently with all other processing, i.e., the Java threads are not stopped during garbage collection.
  5. allel garbage collection mark and sweep algorithm – The parallel garbage collection algorithm stops Java threads when the heap is full and uses all available CPUs to perform a mark and sweep of the heap. Typically a parallel collection has longer pause times than a concurrent collection, but maximizes the application throughput.
We can select a specific garbage collector by using -Xgc:<option>, with option being one of the following:

  • singlecon – Single-space, concurrent garbage collection. This mode reduces application throughput but keeps pause times to a minimum.
  • gencon – Generational, concurrent garbage collection. The gencon mode is better than the singlecon mode for applications that allocate lots of short-lived objects. This mode reduces application throughput but keeps pause times to a minimum.
  • singlepar – Single-space, parallel garbage collection. This mode increases pause times when compared with the concurrent mode but maximizes throughput.
  • genpar – Generational, parallel garbage collection. This mode is generally better than the singlepar mode for applications that allocate lots of short-lived objects. In this mode, a higher number of garbage collections are performed than in the singlepar mode, but the individual pause times are shorter, resulting in lower fragmentation in the old generation space.
  • genconpar – Generational garbage collection. Sets the garbage collection mode to generational with a concurrent mark algorithm and a parallel sweep algorithm.
  • genparcon – Generational garbage collection. Sets the garbage collection mode to generational with a parallel mark algorithm and a concurrent sweep algorithm.
  • singleconpar – Single-space garbage collection. Sets the garbage collection mode to single-spaced with a concurrent mark algorithm and a parallel sweep algorithm.
  • singleparcon – Single-space garbage collection. Sets the garbage collection mode to single-spaced with a parallel mark and a concurrent sweep algorithm.
  • throughput – The garbage collector is optimized for application throughput. This means that the garbage collector works as effectively as possible, giving as much CPU resources to the Java threads as possible. This might, however, cause non-deterministic pauses when the garbage collector stops all Java threads for garbage collection.
  • pausetime – The garbage collector is optimized for short pauses. This means that the garbage collection works concurrently with the Java application when necessary, in order to avoid pausing the Java threads. This inflicts a slight performance overhead to the application, as the concurrent garbage collector demands more system resources (CPU time and memory) than the parallel garbage collector that is used for optimal throughput. The target pause time is by default 200 milliseconds, which can be changed by using -XpauseTarget.
  • deterministic – Optimizes the garbage collector for very short and deterministic pause times. The garbage collector tries to keep the garbage collection pauses below a given pause target. The performance depends on the application and the hardware. Running on slower hardware, with a different heap size or with a large amount of live data can break the deterministic behavior or cause performance degradation over time; faster hardware or a less amount of live data might allows us to set a lower pause target. The pause target for the deterministic mode is by default 30 milliseconds, which can be changed by using -XpauseTarget