Java execute command get output example

The getInputStream() method of Process return the result of what you executed. If there is an error when you invoke the command with Process, using getErrorStream() to get the information. The example code is here.

Java delete file example

Deleting file is a common daily operations. I will show you how to delete file in java. The example code is here.

Java Semaphore example

Semaphore is used to control the number of available threads. Let's say you have a lot of workers and only 5 computers. When workers finish his work he has to release the computer for next worker. Semaphore is good at handle this case. The example of Semaphore is here.

Java CyclicBarrier example

CyclicBarrier is a tool class in concurrent package. It is used to make the thread waiting for other threads. All threads will be waked up when they are all in "wait" state. The sample code is here.

Relational Database tutorial

Common operations for relational database(MySQL & PostgreSQL).

MySQL delete duplicate rows

Duplicate rows will be in you table when you don't use unique key for some reason. In this page I will show you how to remove duplicate rows in MySQL. Let's say the schema of user table is like following.

Linux chkconfig example

chkconfig command can help you check or update the services installed in your environment. Let's say you have installed postgreSQL in your Linux. The script named "postgresql" will be installed in the directory "/etc/init.d/". chkconfig or chkconfig --list will output the services status like following.

Java CountDownLatch example

In java, if you want do something after multiple threads finish CountDownLatch might help you. This class can help you count how many threads is finished. If there is no thread running, it will wake up the main thread. The code example is like following.

How ArrayList increase

As we all know ArrayList use array to store the items. The length of array is fixed. When the array can't hold all items it will increase. I want to know how ArrayList increases the length. I found the source code(JDK1.8) like following.

Java execute command example

Sometimes we need to execute commands in Java. I will show you how to do it in this blog. The code is like following. I assume you use Windows and have installed JDK in your environment. If you use Linux or Mac call runtime.exec("java") will execute java command.

MyBatis show sql log example

Show sql log can help you know the detail of your sql when you use MyBatis. I will show you how to show the sql log when you use MyBatis. The content of pom.xml is like following.

Java heap dump example

We use jmap command to dump the Java heap. Examples are here.

CentOS show version number

In CentOS, run the following command will get the version number.

Java ReentrantLock example

ReentrantLock and synchronized keyword both can make sure only one thread execute the code on the same time. They are similar but not the same. ReentrantLock is more flexible than synchronized. In this page I will show you a simple use case of ReentrantLock.

Linux scp command examples

scp command can help you copy file from remote computer. Here are some examples.