In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the core program module of Scala". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
After reading ManyClients.scala, we basically have a general impression of Scala, and then we start to read the core program module of Scala, starting with src/main/scala/net/kestrel.
You need to introduce some package of scala:
…… Import java.util.concurrent._ import scala.actors. {Actor, Scheduler} import scala.actors.Actor._ import scala.collection.mutable import org.apache.mina.core.session.IoSession.
Several development kits are mainly used in Scala. Java.util.concurrent is a multithreaded framework on the Java 5.0platform. Org.apache.mina is the NIO development package provided by Apache Mina, because walking reading is mainly to understand Scala, so let's not say much about these two packages, let's focus on actor, a very useful multithreaded core package for scala.
Actor, almost occupies a very core position in Scala (it can be said to be the core of Scala). A lot of people hear actor and scala almost at the same time. Or because scala has actor, it is decided to use scala. Of course, scala does not only have actor, in the following code, you can see the design of many languages, so that the design of actor is close to *, concise, highly readable code, can do a lot of work.
But let's start with a simple actor. A complete actor is written as follows:
Import scala.actors.Actor class Redford extends Actor {def act () {println ("A lot of what acting is, is paying attention.")}} val robert = new Redford robert.start
Redford inherits an Actor class (we'll talk about the difference between class and object in Scala later). It has a function, that is, what the thread runs is called act (), and when the thread starts, it executes the act () function. When you need to call the thread, create the object, and then call the robert.start thread to start.
In fact, this method of writing is not very fine, but it just keystrokes a little less than that of Java. There's nothing wrong with that, but looking down, we can put in an extra package for import and write something like this:
Import scala.actors.Actor import scala.actors.Actor._ val paulNewman = actor {println ("To be an actor, you have to be a child.")}
Start a thread directly to handle the business of a branch. Inside the curly braces is the function body of act (). Go back and look at the Kestrel code:
Privateval deathSwitch = new CountDownLatch (1). Def startup (config: Config): Unit = {. / / make sure there's always one actor running so scala 2.7.2 / / doesn't kill off the actors library. Actor {deathSwitch.await}. } def shutdown (): Unit = {. DeathSwitch.countDown}
Pay attention to that comment, open one more thread in the startup system so that the service can run all the time. Until shutdown.
Let's talk about the difference between class and object:
1. For Scala compilers, class does not support any static variables, and when using class, you must first use new to create an instance. Object can be thought of as a Java class with only static content, so the call to it does not need to be created, just call it directly.
two。 In the design pattern, object can be thought of as a Singleton, or singleton pattern. So when calling, you don't need to always have to getInstance to get the handle, like Java.
When we see PersistentQueue.scala, a file contains both class PersistentQueue and object PersistentQueue. It's easier to understand the use of class and object.
This is the end of the content of "what is the core program module of Scala". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.