11.Go 并发
Go 语言支持并发,我们只需要通过 go 关键字来开启 goroutine 即可。
goroutine 是轻量级线程,goroutine 的调度是由 Golang 运行时进行管理的。
goroutine 语法格式:
1 | go 函数名( 参数列表 ) |
1 | go f(x, y, z) |
Go 允许使用 go 语句开启一个新的运行期线程, 即 goroutine,以一个不同的、新创建的 goroutine 来执行一个函数。 同一个程序中的所有 goroutine 共享同一个地址空间。
Go 语言支持并发,我们只需要通过 go 关键字来开启 goroutine 即可。
goroutine 是轻量级线程,goroutine 的调度是由 Golang 运行时进行管理的。
goroutine 语法格式:
1 | go 函数名( 参数列表 ) |
1 | go f(x, y, z) |
Go 允许使用 go 语句开启一个新的运行期线程, 即 goroutine,以一个不同的、新创建的 goroutine 来执行一个函数。 同一个程序中的所有 goroutine 共享同一个地址空间。
Apache 是世界使用排名第一的 Web 服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的 Web 服务器端软件之一。
1. 执行如下命令,安装 Apache 服务及其扩展包。
1 | yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql |
2. 执行如下命令,启动 Apache 服务。
1 | systemctl start httpd.service |
3. 测试 Apache 服务是否安装并启动成功。
Apache 默认监听 80 端口,所以只需在浏览器访问即可。
Jetty 提供了一个 web 服务器和 servlet 容器,另外还提供了对 HTTP/2、 WebSocket、 OSGi、 JMX、 JNDI、 JAAS 和许多其他集成的支持。这些组件是开放源码的,可以免费用于商业用途和分发。
在开发和生产中,Jetty 被广泛应用于各种项目和产品中。Jetty 长期以来深受开发人员的喜爱,因为它可以轻松地嵌入到设备、工具、框架、应用服务器和现代云服务中。
下载地址 https://www.eclipse.org/jetty/download.html
参考文档 Jetty : The Definitive Reference (eclipse.org)
启动和关闭服务脚本
1 | service jetty start |
Apache Tomcat 是 Jakarta EE (正式的 Java EE)技术的一个子集的开放源码软件实现。Apache Tomcat 的不同版本可用于规范的不同版本。规范和相应的 Apache Tomcat 版本之间的映射如下:
| Servlet Spec | JSP Spec | EL Spec | WebSocket Spec | Authentication (JASPIC) Spec | Apache Tomcat Version | Latest Released Version | Supported Java Versions |
|---|---|---|---|---|---|---|---|
| 6.0 | 3.1 | 5.0 | 2.1 | 3.0 | 10.1.x | 10.1.0-M16 (beta) | 11 and later |
| 5.0 | 3.0 | 4.0 | 2.0 | 2.0 | 10.0.x | 10.0.22 | 8 and later |
| 4.0 | 2.3 | 3.0 | 1.1 | 1.1 | 9.0.x | 9.0.64 | 8 and later |
| 3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.81 | 7 and later |
| 3.1 | 2.3 | 3.0 | 1.1 | N/A | 8.0.x (superseded) | 8.0.53 (superseded) | 7 and later |
| 3.0 | 2.2 | 2.2 | 1.1 | N/A | 7.0.x (archived) | 7.0.109 (archived) | 6 and later (7 and later for WebSocket) |
| 2.5 | 2.1 | 2.1 | N/A | N/A | 6.0.x (archived) | 6.0.53 (archived) | 5 and later |
| 2.4 | 2.0 | N/A | N/A | N/A | 5.5.x (archived) | 5.5.36 (archived) | 1.4 and later |
| 2.3 | 1.2 | N/A | N/A | N/A | 4.1.x (archived) | 4.1.40 (archived) | 1.3 and later |
| 2.2 | 1.1 | N/A | N/A | N/A | 3.3.x (archived) | 3.3.2 (archived) | 1.1 and later |