We can use clone method to clone an object. This is a native method in Object (make it faster). If you want to use this method you need to implement cloneable interface. If you want to use this method in different package do not forget change this method to be public. The example code is here.
In this blog I will show you how to calculate two milliseconds in Java8. Java8 adds a new package java.time. It is easy to handle time by using the class in this package. The example code is here.
Deadlock means multiple workers(threads) are waiting for each other release common resource. In this blog I will create a deadlock example. Two workers both need lock1 and lock2 to finish the task. When one hold lock1 and another hold lock2 they are both waiting for another to release the lock. This state is called dead lock.
retainAll method is used to remove the elements which not in both collections. The example code is here.
Today I solve a problem about missing http header. I add some extra information in http headers when I request server. The code works well in my local environment. When I deploy it on the remote machine some http headers are missing. After google I solve the problem.
In this page I will show you when static inner class is initialized. I write a demo to help you to understand it. All static fields (include inner class) is initialized when the class is loaded.
The key words group by is used to divided records into several groups. Let's say you have a table like following. This table is the score of course for different students. Table name is score_info
For linux mint there are many service scripts in the directory /etc/init.d. Most of them will be executed when user login. Linux uses different directory (such as /etc/rc?.d/) to mark which service and when to run. If you don't want one service auto start you need to remove the link from the directory or to use update-rc.d command like following.
ReadWriteLock is used in the scenario that reading operation is more frequent than writing. It is more efficient than synchronized method. Multiple read threads do not block each other, only write thread blocks read thread. The sample code is here.
Dynamic proxy is commonly used in popular java frameworks, such as Spring, MyBatis and so on. There are other ways to implement proxy by using aspect or javassit and so on third part frameworks. In this page I will show you JDK dynamic proxy.
When I POST some xml data to server by using chrome I got the error message like following.
There are 6 states for Java Thread. From JDK comment it says that A thread can be in only one state at a given point in time. In this page I will show you different states in thread life cycle. Hope the sample code can help you understand the states better.
Template method pattern is commonly used in this scenario that main logic is stable but sub steps are not. Let's say you want to add export function in your system. For different data source there are different way to export data, but the main steps are the same: "getData", "processData" and "export". Let's try to use template method pattern in this example.
After downloading and unzipping the tar.gz file of IDEA I can start it by executing idea.sh. But I want to add it in Linux mint applications menu. For Linux mint the applications menu info is in / usr / share / applications /. Creating the file idea.desktop in this directory. The content is like following.
I have an old laptop with 4G memory and T6600 CPU. It installed Windows7 before and it runs slower and slower recently. I decide to install linux on it. Finally I choose Linux mint with xfce. It is not very beautiful but it's lightweight and use less memory. For the default Chinese fonts is not very clear. After google I use following command to make the fonts become clearer.