Recently I started working on a Spring Boot Kotlin project. I have been using Spring Boot with Java in the past, and I love its simple and flexible design, especially the autowire function. Autowiring makes every module loosely coupled from others, which is one of the most powerful features in Spring Boot. However, I created a new Service class and injected it into another service, as shown in the code below:
@Service object CoolService { // ...... }
class MyController { @Autowired var coolService: SomeCoolService // ...... }
But the autowire was not applied, coolService in MyController was null. Can you figure out why?
I searched the web but found no answer. Yes, ChatGPT listed many reasons, but none of them were correct.
Finally, I changed CoolService from object to class. It worked!
Spring Boot should output a warning if it cannot autowire an object.
Years ago, I worked at Gameloft as a game server developer. Our server needed to handle player actions in real-time. Its main loop ran at a fixed speed of 10 FPS, meaning the server would process data every 100 milliseconds. If the processing finished in less than 100 ms, the server would sleep until the start of the next 100 ms period.
To achieve this, the server called the Linux times() function before and after the processing step to calculate elapsed time, as shown below:
int64 beginTime = getCurTime(); // hadling player data int64 endTime = getCurTime(); int64 timeElapsed = endTime - startTime;
You can see that timeElapsed is always expected to be a positive number.
One day, all the servers crashed simultaneously. Upon inspecting the core dump, I discovered the cause: timeElapsed was calculated as -900 ms, meaning the server’s clock had somehow gone backward by a second. Every single server was affected.
Was this real-world time travel?
I then recalled a news article I had recently read: About Leap Seconds. We all know about leap years: the Earth’s orbit around the Sun isn’t exactly 365 days, it is closer to 365.24 days. Leap years help ensure our calendars remain aligned with the Earth’s orbit. Similarly, the Earth’s rotation isn’t perfect 24 hours, it varies due to climatic and geological factors. To keep the world clock aligned with the Earth’s rotation, adjustments are made when the difference approaches one second. These adjustments are called leap seconds.
The most recent leap second, at the time, had been applied on 2016-12-31, the exact date our servers crashed. At midnight, all server’s time moved back from 00:00:00 to 23:59:59 of the previous day.
When you create a Vue3 project with Vite, it is initially configured to be accessible only via localhost. To enable accessfrom other computer, modify vite.config.js file by adding the folloing configuration:
Many years ago, I visited Shanghai for my first time. It was very early in the moring when I got off the train and went to the office building where my company was located. In the lobby, there was a long line of people. What were they doing? Was there free breakfast? The truth shocked me: They were lining up to wait for the elevator! You see, back then, no one in Beijing lined up to wait for an elevator. We would all crowd around the elevator doors. This was my first impression of Shanghai: It was 20 years ahead of Beijing in terms of civilization.
But this year, the pandemic situation in Shanghai has made me think it is 20 years behind in terms of civilization.
A friend lives in an apartment. One day, the building management company posted an announcement: “To reduce fire risk, all residents should remove personal items from the public corridor within 3 days, or they will be discarded after that.” So my friend moved a lot of unused items to the public corridor, expecting them to be removed for free. However, the building management company didn’t do what it said…
Thor Heyerdahl was an anthropologist from Norway. While conducting research in Polynesia, relics and local tales led him to believe that the original inhabitants came from South America in the 5th century AD. However, no one believed his theory.
To prove his hypothsis, he gathered five volunteers, and build a raft named “Kon-Tiki” using traditional indigenous techniques. In Apirl 1947, they set off from Peru on this raft. After spending 101 days and traveling 4900 miles, they arrived in Polynesia, create a remarkable milestone in the history of human sailing.
This morning, when I got into the car, a red tire pressure alarm light came on. I checked all 4 tires, and their pressure was around 27 PSI, quite low. Using a pump, I inflated them to 36 PSI. But the tire pressure alarm light was still on! Could it be the backup tire? Yes, the backup tire’s pressure was also 27 PSI. After inflating it to 36 PSI, the alarm finally turned off.
Kidnapping, internment, rape, and intentional injury are all felonies. However, the rediculous thing is that when you combine all these, it becomes human trafficking - a misdemeanor.
If a crime requires waiting for mayor to handle, it means the law is useless.