Singleton Pattern

What is the Singleton Pattern? The Singleton Pattern, also known as the Singleton, is a commonly used software design pattern and is one of the creational patterns. In this design pattern, the class of the singleton object must ensure that only one instance exists. Pros and Cons Pros: There is only one instance in memory, reducing memory overhead. Cons: It violates the Single Responsibility Principle, and there is no interface,

TCP Study for Interviews

What is TCP TCP is a full-duplex, byte-stream protocol based on the IP protocol. TCP provides end-to-end accurate transmission. Acknowledges each byte Handles poor network conditions Timeout retransmission Congestion control Efficiency improvement Uses sliding window protocol TCP is a connection-oriented protocol. Since it is connection-oriented, how is this connection established? That is, the following question is how to establish a virtual link using a three-way handshake.

How Actor Handles Blocking Messages

I noticed in the business code that a lot of import scala.concurrent.ExecutionContext.Implicits.global is used as the thread pool for executing Future inside the Actor. I didn’t think there was a problem before. But after reading the akka source code, it seems a bit inappropriate. Let’s briefly talk about the architecture of Actor When an Actor sends a message to another Actor, it sends this message to the recipient’s mailbox The mailbox is a class that implements Runnable, so it can be executed by a thread pool.

Analysis of Akka Source Code

1 2 3 4 5 6 7 8 9 10 11 12 13 14 object Main1 extends App { val system = ActorSystem("HelloSystem") val jazzListener = system.actorOf(Props[Listener]) val musicListener = system.actorOf(Props[Listener]) system.eventStream.subscribe(jazzListener, classOf[Jazz]) // jazzListener 订阅 Jazz 事件 system.eventStream.subscribe(musicListener, classOf[AllKindsOfMusic]) // musicListener 订阅 AllKindsOfMusic 以及它的子类 事件 // 只有 musicListener 接收到这个事件 system.eventStream.publish(Electronic("Parov Stelar")) // jazzListener

How to learn Scala

Background: When I first came to a company with Scala as its technology stack, I spent a long time setting up the environment. After finally getting the project up and running, I found the code inside to be very strange. There were no loops, and data operations were a function nested within another function. This was very puzzling. So, driven by business needs and curiosity, I began to learn about Scala.