Snippets

Những đoạn code ngắn, tái sử dụng được, trích từ các bài viết trên blog.

Bước 1: Tạo connection

Trích từ bài “Điều gì xảy ra khi MySQL thực thi câu lệnh SELECT?”

js
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------+
| Id | User | Host      | db   | Command | Time | State | Info |
|  6 | root | localhost | NULL | Sleep   | 736  |       | NULL |
|  7 | root | localhost | NULL | Query   | 0    | init  | 0    |
+----+------+-----------+------+---------+------+-------+------+
2 rows in set (0.00 sec)

Bước 2: Phân tích cú pháp SQL

Trích từ bài “Điều gì xảy ra khi MySQL thực thi câu lệnh SELECT?”

js
mysql> select * form Member;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'form Member at line 1

Giai đoạn tiền xử lý (Preprocessor)

Trích từ bài “Điều gì xảy ra khi MySQL thực thi câu lệnh SELECT?”

js
mysql> select * from test;
ERROR 1146 (42S02): Table 'mysql.test' doesn't exist

Nêu đặc điểm của các biến, phương thức, lớp có từ khóa final?

Trích từ bài “Top 10 Câu Hỏi Phỏng Vấn Về Java Core”

js
final int x = 10;
// Không thể gán lại giá trị cho x

Phân biệt giữa override và overload?

Trích từ bài “Top 10 Câu Hỏi Phỏng Vấn Về Java Core”

js
public class Example {
    public void printInfo(String message) {
        System.out.println("Message: " + message);
    }

    public void printInfo(int number) {
        System.out.println("Number: " + number);
    }
}

Triển khai Distributed Lock với Redis

Trích từ bài “Distributed Lock và Cách Triển Khai với Redis”

js
func update() {
   try {
       // Try lock "key" with TTL = X seconds in Y seconds
       if(tryLock(key, value, X, Y)) {
           // Handle get, calculate and update resource
           // Return
       }
   } finally {
       unLock(key, value)
   }
   //
   throw Exception("Try lock timeout")
}