Monday, March 28, 2016

PostgreSQL performance Analysis


  1. http://engineering-blog.alphasights.com/how-to-stop-worrying-and-love-the-index/
  2. http://stackoverflow.com/questions/6592626/what-is-a-bitmap-heap-scan-in-a-query-plan
  3. https://devcenter.heroku.com/articles/postgresql-indexes
  4. http://michael.otacoo.com/postgresql-2/postgres-9-4-feature-highlight-lossyexact-pages-for-bitmap-heap-scan/
  5. http://pglearner.blogspot.com/2015/01/learning-bitmap-index-scan-recheck-cond.html
  6. http://www.postgresql.org/message-id/12553.1135634231@sss.pgh.pa.us
  7. http://dba.stackexchange.com/questions/119386/understanding-bitmap-heap-scan-and-bitmap-index-scan?newreg=52a072b9a8fa49fc989ed058adda8505
  8. http://dba.stackexchange.com/questions/106264/recheck-cond-line-in-query-plans-with-a-bitmap-index-scan
  9. http://stackoverflow.com/questions/410586/what-is-the-difference-between-seq-scan-and-bitmap-heap-scan-in-postgres
  10. http://stackoverflow.com/questions/10145037/understanding-postgres-explain-w-bitmap-heap-index-scans
  11. http://ask.use-the-index-luke.com/questions/148/why-is-this-postgres-query-doing-a-bitmap-heap-scan-after-the-index-scan
  12. http://www.postgresql.org/docs/8.1/static/performance-tips.html
  13. http://www.tech-recipes.com/rx/47637/inner-and-left-outer-join-with-where-clause-vs-on-clause/
  14. http://stackoverflow.com/questions/15706112/why-and-when-a-left-join-with-condition-in-where-clause-is-not-equivalent-to-the
  15. http://stackoverflow.com/questions/4752455/left-join-with-where-clause
  16. https://www.digitalocean.com/community/tutorials/how-to-create-remove-manage-tables-in-postgresql-on-a-cloud-server
  17. https://momjian.us/main/writings/pgsql/aw_pgsql_book/node195.html
  18. http://www.revsys.com/writings/postgresql-performance.html
  19. http://genius.com/Genius-engineering-team-one-weird-trick-to-make-postgresql-15000x-faster-annotated
  20. https://en.wikipedia.org/wiki/Bitmap_index
  21. http://stackoverflow.com/questions/6592626/what-is-a-bitmap-heap-scan-in-a-query-plan
  22. http://engineering-blog.alphasights.com/how-to-stop-worrying-and-love-the-index/
  23. http://www.postgresql.org/message-id/6638.1456795348@sss.pgh.pa.us
  24. https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/
  25. http://stackoverflow.com/questions/6777456/list-all-index-names-column-names-and-its-table-name-of-a-postgresql-database
  26. https://devcenter.heroku.com/articles/postgresql-indexes
  27. http://www.tutorialspoint.com/postgresql/postgresql_indexes.htm
  28. https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server
  29. https://developers.google.com/identity/protocols/OAuth2InstalledApp#handlingtheresponse

Sunday, March 27, 2016

java path checking

https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

Monday, March 21, 2016

Design Pattern and LRUCache

hibernate improve database performance

hibernate improve database performance


  1. In the query string, you should use jdbc placeholder? Or use named parameters: Do not use the query string value instead of the very values.
  2. Flush affect performance, frequently refreshed affect performance, minimize unnecessary refresh. 
  3. Cascade strategy, a few to several relationships set correctly cascade strategy, to think clearly in the operation target A cascade operation, while the need for an object B, such as one to many relationship between father and son, the father removed one, required level United delete child many, this time can be set to one end of this cascade = "delete", so when you delete one, the child is automatically deleted, but the pair does not affect the parent. Cascade has other property values, as long as the settings are correct, you can improve performance. 
  4. Lazy policy set correctly delay loading strategy will also enhance the performance, one to many or many to many, the total delay should normally be loaded into the memory of many of the party. Set lazy = "true", first send sql statements to load itself into memory only when needed to load Cascading objects; lazy = "false", is simultaneously loaded into memory objects themselves and cascade. 
  5. In addition to the performance of the collection (set, list, map, array ), should be set up correctly. 
  6.  The proper use of third-party cache, read frequently writes small operating conditions, the use of third-party cache can significantly improve performance, such as ehcache caching strategies have: read-only, read-write and notstrict-read-write.

Friday, March 18, 2016

Good links for performance

ArrayList equals for list of array

Omio Bani


  1. http://stackoverflow.com/questions/36069596/java-how-to-convert-string-to-string-with-different-charset


A string doesn't have an encoding - or it's always UTF-16, if you want to think of it like that. There's no such thing as "a UTF8 string". If you've converted some binary data into a String using the wrong encoding, you're in trouble already


  1. http://stackoverflow.com/questions/36063803/why-the-containvalue-method-returning-true-even-if-i-override-the-hashcode-met

Hash maps only use hash codes to find keys efficiently. When you ask the map to find a value, it basically has to iterate over all its entries, at which point there's no point in using hashCode(), so it just calls equals.
If you try the map the other way round, with Test as the key instead of the value, that won't work without overriding hashCode.

Java Garbase collection basics

AJAX and JAX-RS

Wednesday, March 16, 2016

java.lang.IllegalStateException while starting Tomcat Server

on Spring with Hibernate application, application is working fine but while starting tomcat server, im getting below Exception.
Can anybody explain why this exception occurring and how to resolve it??
INFO: Illegal access: this web application instance has been stopped already.  Could not load java.net.BindException.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
            java.lang.IllegalStateException
                at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600)
                at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
                at com.mysql.jdbc.SQLError.createLinkFailureMessageBasedOnHeuristics(SQLError.java:1220)
                at com.mysql.jdbc.exceptions.jdbc4.CommunicationsException.<init>(CommunicationsException.java:57)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
                at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
                at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3270)
                at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1659)
                at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4296)
                at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1265)
                at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2667)
                at java.lang.System$2.invokeFinalize(Unknown Source)
                at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
                at java.lang.ref.Finalizer.access$100(Unknown Source) 
                at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

Answer:

I want to give you couple of choices. You can try it. Any option can fulfill your demand.
  1. Restart your tomcat and apache server because a long time of using, it keeps older version of your application.
  2. Clean your tomcat temp directory and restart
  3. As stated in error,
The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
It may be the real cause that at this moment you are in debugging mode and it doesn't clear the running thread. so remove your break point and run it not debugging
  1. If your code contains any kind of thread which are not properly terminated, then this type of error may occur. That you have init() method but no destroy() method, then this type of error may occur. For details, you can follow the link -http://www.javaspecialists.eu/archive/Issue056.html
  2. if the webapp has stopped, or is stopping, that means that the .war file or WEB-INF/web.xml timestamp changed, and the webapp might be reloading. Please check timestamp is OK or not.
  3. To turn it off, set reloadable="false" in the context definition of your app. It might be tomcat's server.xml. In details solution: The tomcat's server.xml of the reloadable Context is set to false. For example:
Context path="/expert" docBase="expert" debug="0" reloadable ="false"/>
The solution is easy, as long as the tomcat's server.xml in reloadable = "true" into false on the line, but to do so would lose the advantage of hot deployment, and for the development is not very convenient, simply change it or not. This error does not matter.
Error principle:
The reason is because the tomcat restart, because the previous tomcat thread has not completely shut down, restart tomcat will report this exception, but this does not affect the normal use, just jump abnormal annoying people. Used hibernate, spring or other large components, when a WEB application system has a lot of class,
if you turned the Tomcat reloadable = true, then whenever the relevant documents change, Tomcat stops web app and frees up memory, and then reload web app. it may be a huge project. So we always think if there is only a certain class of overloaded functions, will greatly meet our debugger.
UPDATE: For code related issue
First, I want to tell you that I have given you some solutions for tomcat basis. Now I want to give you a solution for code basis. Would you please cross check your code with this issue? Please follow the URL.
  1. http://www.coderanch.com/t/660126/Wiki/Illegal-State-Exception
UPDATE: For MySQL related issue
  1. There are 2 issues.
    • This web application instance has been stopped already. Could not load java.net.BindException.
    • This web application instance has been stopped already.Could not load com.mysql.jdbc.
This is because the MySQL JDBC driver on the application under the WEB-INF/lib directory, in the re-release of its loaded twice, so long as it can be copied to %TOMCAT_HOME%/lib can solve the problem. We can solve these two anomalies MySQL drivers from the WEB-INF/lib folder moved to%TOMCAT_HOME%/lib.
  1. I suspect this might be happening after the web application is restarted, where it's down for a short period of time. Then some finalize() method in the code is probably trying to do some cleanup too late. Whether or not that's in your code or the MySQL driver I can't say. You definitely should only have one version of a jar in a directory at a time. You might want to upgrade it to the latest (5.1.38 right now) in case something has been fixed that might be affecting you.(Number 9 is copied from @WhiteFang34)

Roshogolla

Thursday, March 10, 2016

input miss match exception

https://examples.javacodegeeks.com/java-basics/exceptions/java-util-inputmismatchexception-how-to-solve-inputmismatchexception/

Wednesday, March 9, 2016

What is so bad about singletons?

LinkedHashMap vs ConcurrentHashMap

How toto make LinkedHashMap thread safe?

java.util.Collections.synchronizedMap(map) returns a synchronized (thread-safe) map backed by the specified map.
You can anonymously extend LinkedHashMap to change the behavior of removeEldestEntry(...), then wrap the instance of the anonymous class in a synchronized map. You didn't mention what type parameters you require, so I'm using <String, Integer> in this example.
Map<String, Integer> map = Collections.synchronizedMap(new LinkedHashMap<String, Integer>() {
   private static final long serialVersionUID = 12345L; // use something random or just suppress the warning
   @Override
   protected boolean removeEldestEntry(Entry<String, Integer> eldest) {
      return size() > MAX_SIZE; // how many entries you want to keep
   }               
});
Original Link:
http://stackoverflow.com/questions/28653889/java-thread-safe-linkedhashmap-implementation

IOC containers and DI pattern

Online IDE for JAVA and others

Comparable Vs CompareTo

Tuesday, March 8, 2016

Learn Servlet with multithreaded system

Heap Space Vs Permgen Space

Simply
  • Heap space: All live objects are allocated here.
  • Stack space: Stores references to the object for variable in method call or variable instantiation.
  • Perm space: Stores loaded classes information
For example:
Student std = new Student();
after executing the line above memory status will be like this.
  • Heap: stores "new Student()"
  • Stack: stores information about "std"
  • Perm Space: stores information about Student class
Stack also stores primitive literals

Heap Space:

java.lang.OutOfMemoryError:Java heap space

Java applications are only allowed to use a limited amount of memory. This limit is specified during application startup. To make things more complex, Java memory is separated into two different regions. These regions are called Heap space and Permgen (for Permanent Generation):
OutOfMemoryError: Java heap space
The size of those regions is set during the Java Virtual Machine (JVM) launch and can be customized by specifying JVM parameters -Xmx and -XX:MaxPermSize. If you do not explicitly set the sizes, platform-specific defaults will be used.
The java.lang.OutOfMemoryError: Java heap space error will be triggered when the application attempts to add more data into the heap space area, but there is not enough room for it.
Note that there might be plenty of physical memory available, but thejava.lang.OutOfMemoryError: Java heap space error is thrown whenever the JVM reaches the heap size limit.

What is causing it?

There most common reason for the java.lang.OutOfMemoryError: Java heap space error is simple – you try to fit an XXL application into an S-sized Java heap space. That is – the application just requires more Java heap space than available to it to operate normally. Other causes for this OutOfMemoryError message are more complex and are caused by a programming error:
  • Spikes in usage/data volume. The application was designed to handle a certain amount of users or a certain amount of data. When the number of users or the volume of data suddenly spikes and crosses that expected threshold, the operation which functioned normally before the spike ceases to operate and triggers the java.lang.OutOfMemoryError: Java heap space error.
  • Memory leaks. A particular type of programming error will lead your application to constantly consume more memory. Every time the leaking functionality of the application is used it leaves some objects behind into the Java heap space. Over time the leaked objects consume all of the available Java heap space and trigger the already familiar java.lang.OutOfMemoryError: Java heap space error.


Permgen space:

java.lang.OutOfMemoryError:Permgen space

Java applications are only allowed to use a limited amount of memory. The exact amount of memory your particular application can use is specified during application startup. To make things more complex, Java memory is separated into different regions which can be seen in the following figure:
java.lang.outofmemoryerror: Permgen space
The size of all those regions, including the permgen area, is set during the JVM launch. If you do not set the sizes yourself, platform-specific defaults will be used.
The java.lang.OutOfMemoryError: PermGen space message indicates that thePermanent Generation’s area in memory is exhausted.

What is causing it?

To understand the cause for the java.lang.OutOfMemoryError: PermGen space, we would need to understand what this specific memory area is used for.
For practical purposes, the permanent generation consists mostly of class declarations loaded and stored into PermGen. This includes the name and fields of the class, methods with the method bytecode, constant pool information, object arrays and type arrays associated with a class and Just In Time compiler optimizations.
From the above definition you can deduce that the PermGen size requirements depend both on the number of classes loaded as well as the size of such class declarations. Therefore we can say that the main cause for the java.lang.OutOfMemoryError: PermGen space is that either too many classes or too big classes are loaded to the permanent generation.

Resource Link:

  1. https://plumbr.eu/outofmemoryerror/java-heap-space
  2. https://plumbr.eu/outofmemoryerror/permgen-space
  3. http://stas-blogspot.blogspot.in/2011/07/most-complete-list-of-xx-options-for.html#UseConcMarkSweepGC
  4. https://www.javacodegeeks.com/2013/12/decoding-java-lang-outofmemoryerror-permgen-space.html
  5. http://www.javavillage.in/reasons-outofmemory-permespace.php
  6. https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html
  7. http://www.dynatrace.com/en/javabook/other-java-memory-issues.html