WEB-INF directory in jee applicaiton

The Servlet 2.4 specification says this about WEB-INF: A special directory exists within the application hierarchy named WEB-INF. This directory contains all things related to the application that aren’t in the document root of the application.The WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF…

Java 8 默认方法和多继承

  以前经常谈论的Java对比c++的一个优势是Java中没有多继承的问题。 因为Java中子类只能继承(extends)单个父类, 尽管可以实现(implements)多个接口,但是接口中只有抽象方法,方法体是空的,没有具体的方法实现,不会有方法冲突的问题。 这些都是久远的说法了,自从今年Java 8发布后, 接口中也可以定义方法了(default method)。 之所以打破以前的设计在接口中增加具体的方法, 是为了既有的成千上万的Java类库的类增加新的功能, 且不必对这些类重新进行设计。 比如, 只需在Collection接口中增加default Stream<E> stream(), 相应的Set和List接口以及它们的子类都包含此的方法, 不必为每个子类都重新copy这个方法。 这是一个折衷的设计,带来的问题就是为Java引入了多继承的问题。 我们知道, 接口可以继承接口, 类可以继承类和实现接口。 一旦继承的类和实现的接口中有相同签名的方法, 会出现什么样的状况呢? 本文将探讨各种情况的多继承, 以便能清楚的理解Java多继承的规则。 接口继承多个父接口 假定有三个接口Interface A, Interface B, Interface C, 继承关系如下: +—————+ +————+ | Interface A | |Interface B | +———–^—+ +—^——–+ | | | | | | +-+————+–+ | Interface C| +————+…

spring mvc root url map with tomcat

We typically use @RequestMapping(“/”) to map the root url. It might not work with tomcat sometimes. One reason was that that something (Tomcat?) was forwarding from “/” to “/index.jsp” when I had the file index.jsp in my WebContent directory. When I removed that, the request did not get forwarded anymore. So the important thing here is: Don’t…

page-break property in css

There isn’t an actual page-break property in CSS. It is actually a set of 3 properties: page-break-before, page-break-after and page-break-inside. These properties help define how the document is supposed to behave when printed. For example, to make a printed document more book-like. Properties page-break-before The page-break-before property adds a page-break before the element to which…

shim and polyfill

A polyfill is code that detects if a certain “expected” API is missing and manually implements it. E.g. if (!Function.prototype.bind) { Function.prototype.bind = …; } A shim is code that intercepts existing API calls and implements different behavior. The idea here is to normalize certain APIs across different environments. So, if two browsers implement the…

5 Coding Hacks to Reduce GC Overhead

Some background The GC is built to handle large amounts of allocations of short lived objects (think of something like rendering a web page, where most of the objects allocated become obsolete once the page is served). The GC does this using what’s called a “young generation” – a heap segment where new objects are…

Java Deadlock Example and How to analyze deadlock situation

Deadlock is a programming situation where two or more threads are blocked forever, this situation arises with at least two threads and two or more resources. Here I have written a simple program that will cause deadlock scenario and then we will see how to analyze it. Java Deadlock Example In above program SyncThread is…

Weak References in java

Normally the Java garbage collector plays safe. It will only free up the memory used by an object when that object can no longer be accessed by the program. Once an object become impossible to reach it is eligible for collection, and eventually its memory will be reclaimed. This eliminates one of the most common…

hibernate caching strategy

For databases, the following applies to all levels: the best database accesses are those that do not have to be carried out. For this, caches are used within the database and also in Hibernate and JPA. Caching is relatively complex and one of the most misunderstood concepts of Hibernate. There are three different caches: First…

batch / bulk insert/update in jpa/hibernate with flush and clear

For JPA use entity manager to do flush/clear For hibernate basically just switch the entity manager with hibernate session. When making new objects persistent flush() and then clear() the session regularly in order to control the size of the first-level cache. The suggest batch size is 20-50 by hibernate. However I found 1500 is good…

that=this in javascript

Watch Out: Callbacks And Closures Sometimes Do Not Play Nicely  Of course there are always gotchas with JavaScript. Lets define a callback function: 1 2 3 4 5 6 7 8 9 10 11 var createCallBack = function() { //First function return new function() { //Second function this.message = “Hello World”; return function() {…