Java wait notify consumer producer example

wait, notify and notifyAll are all method of Object. It means that every object in java can be a lock monitor. When you use synchronized you get the lock of object. Use synchronized on the method current thread will get the lock of instance. If you add synchronized on a static method that means current thread will get the lock of this Class. These 3 methods can not be used without synchronized (you can release the lock without geting it).

Java URL decode encode example

When you send GET request to server, you need to encode the data which contained in the url.In this way can make sure the data you send could be received by server correctly. Certainly, serve has to decode the data before using them. The example is like following.

Java quick sort example

Quicksort is one of the most common sorting algorithms. The logic of Quicksort is choosing a number (called pivot) and divide the rest into two parts. After first sorting the numbers on the left side are all less than pivot and the numbers on the right side are all bigger than pivot. Then do the same thing for left and right part.

MySQL create multiple indexes in one sql

The statement of creating index on table will lock the table.It will cost a long time if you create multiple indexes in a big table. You can use ALTER TABLE ... to create or drop multiple indexes in one sql. The example is here.

Linux no space left on device

If the message No space left on device appears that means you need clear the file on your system or add new disk for your computer. "No space" not only means no free disk, it may also mean there is no iNodes in your system.

MyBatis tutorial

MyBatis is a Java persistence framework. It is easy to use and learn. This tutorial shows the most common scenarios.

MyBatis first level cache example

The first level cache is enabled by default in MyBatis. It will cache the result after querying data from database. The second time you query MyBatis won't hit db. The first level cache is for session. If the session is close the cache will be cleared. I assume that you have created database and insert some data in your table.

PostgreSQL desc table

In MySQL you can use desc to show the details of table. There is no desc command in PostgreSQL, but you can use \d or \d+ to show the table detail.

Spring Boot Swagger2 example

Swagger can help you generate document for your restful API. This blog will show you how to use it. I assume that you have known how to use Spring Boot. The structure of example project is like following.

Java Compare JSON string example

Use jsonassert framework to compare two json are same or not. It only compare the content of them. The example code is here;

PostgreSQL list all tables

Use \d or \d+ in psql command to show all tables. \d+ will show additional detail of tables;

Spring ResponseBody without null field

The annotation @ResponseBody can help you convert object to json. Sometimes if the field of object is null the json returned like following.

Linux list and set environment variable

Use set command to list all environment variables. They are like following in my computer.

Linux show folder(directory) size

Use du command to show the size of folder. Before testing this command we will create a directory and a file.

PostgreSQL switch database

In PosgreSQL there are several ways to switch database.