Monthly Archives: July 2016

Tomcat gets stuck during start up?

It takes more than 5 minutes for your tomcat to startup.  You think it’s your application’s program. But when you download a clean Tomcat (of the same version) can run it without dropping in any of your applications, it still gets stuck.  It may be caused by this: According to my just wasted 2 […]

Call Java compiler programatically

You don’t need to add any dependency private static void doCompile(File sourceDir) throws SomeException { System.out.println(“Compiling started”); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector diagnostics = new DiagnosticCollector(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Collection files = FileUtils.listFiles(sourceDir, new String[] { “java” }, true); Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles(files); List compilerOptions = Arrays.asList(“-source”, “1.6”, “-target”, “1.6”); JavaCompiler.CompilationTask task […]

Tips for traversing a tree with stacks

  Here are the tips of my solution: You always push the root to the stack first The most difficult part is: when you see a node on the top of element, should you go on to push its children, or pop it to print it?  For pre-order traversal, you can pop it then push […]

Propagate data change from RDBMS to Solr

Basically, you will use solr’s DataImportHandler to do the importing. Hit http://solr-server:port/solr/db/dataimport?command=full-import to do a full import. Hit http://solr-server:port/solr/dataimport?command=delta-import to do a delta import So, what’s the delta? This is configured in some data-config.xml: deltaQuery=”select id from item where last_modified > ‘${dih.last_index_time}'” So it requires the table on your database must have a column called […]

No PermGen any more in Java 8

All the class definitions now go to an area called "Metaspace".  GC based on references is faster than it was in PermGen. Metaspace is in native-memory zone.  Its size is unlimited by default.  So as long as your machine has enough memory, OOM will not happen.  You can still set a limit to it with […]

G1 v.s. CMS

G1 also aims at "low pause", and it can work well on large heaps(over 4G) .   CMS, on the other hand, are not designed for large heaps. And CMS requires more configuration. 

Why I am not a fan of Hibernate

Rich Domain Model + Lazy-loading cause problems Hiberntate encourages rich domain model over table model, that is,  A.b instead of A.bId You must enable lazy-loading, otherwise there will be performance issues If you are not in a hibernate session, A.b will be invalid ("Partial Materialization" problem) To make user you are in a hibernate session, […]