rabbitmq进阶一

上一篇文章有讲到rabbitmq的安装、web管理端和springboot简单集成rabbitmq

本文重点介绍rabbitmq相关api的使用

按照官网常用的五种模式的顺序:HelloWorld、Work queues、Publish/Subscribe、Routing、Topics

模式简单介绍

HelloWorld

一个生产者,一个队列,一个消费者。

一个demo,实际很少使用。

Work queues

在多个消费者之间分配任务,竞争消费模式。

Publish/Subscribe

发布订阅模式,同时向多个消费者发送消息。

Routing

选择性的接收消息

Topics

基于表达式接收消息

模式具体使用(rabbitmqclient)

HelloWorld

创建maven项目并且引入依赖

    <dependencies><dependency><groupId>com.rabbitmq</groupId><artifactId>amqp-client</artifactId><version>5.9.0</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version></dependency></dependencies>

创建工具类,用于处理连接和信道的创建,以及他们的关闭

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class ConnectionUtils {public static Connection createConnection() throws IOException, TimeoutException {ConnectionFactory connectionFactory = new ConnectionFactory();
//        connectionFactory.setHost("localhost");//默认主机:localhost
//        connectionFactory.setPort(5672);//默认端口5672
//        connectionFactory.setUsername("guest");//默认用户名:guest
//        connectionFactory.setPassword("guest");//默认密码:guest
//        connectionFactory.setVirtualHost("/");//默认虚拟主机:/return connectionFactory.newConnection();}public static void closeConnection(Connection connection, Channel channel) throws IOException, TimeoutException {channel.close();connection.close();}
}

创建消费者

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class HelloWorldConsumer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicConsume("my helloworld queue",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

创建生产者

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class HelloWorldProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicPublish("","my helloworld queue",null,"helloworld消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

 若要保证rabbitmq重启后消息仍然存在,生产者发送消息时需要设置props参数

channel.basicPublish("","my helloworld queue", MessageProperties.PERSISTENT_TEXT_PLAIN,"helloworld消息内容".getBytes(StandardCharsets.UTF_8));

 开启手动ack,消费者接收到消息时,需要手动发送ack确认后消息才会真正从队列中删除

        channel.basicConsume("my helloworld queue",false,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));channel.basicAck(envelope.getDeliveryTag(),false);}});

Work queues

创建消费者,与上面helloworld模式代码基本一致,将原有的创建消费者的代码重复一遍

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class HelloWorldConsumer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();/*声明一个名称是my helloworld queue,持久化,非独享,非自动删除的队列durable – 是否持久化,为true时重启rabbitmq服务,会保留原有的队列exclusive – 是否独享,为true时连接一旦断开,会自动删除队列autoDelete 是否自动删除,为true时一旦队列被消费,会自动删除队列*///若队列已存在,这些参数必须与队列一致,若队列不存在则创建channel.queueDeclare("my helloworld queue",true,false,false,null);channel.basicConsume("my helloworld queue",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("helloworld consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

创建生产者,与上面helloworld模式代码基本一致,这里连续发送10条消息

package org.cc;import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class WorkProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.queueDeclare("my work queue",true,false,false,null);for (int i = 0; i < 10; i++) {channel.basicPublish("","my work queue", MessageProperties.PERSISTENT_TEXT_PLAIN,("work消息内容"+i).getBytes(StandardCharsets.UTF_8));}ConnectionUtils.closeConnection(connection,channel);}
}

 从消费者的控制台可以看到两个消费者轮流接收到消息

Publish/Subscribe

消费者

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class Subscriber {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("fanout exchange", BuiltinExchangeType.FANOUT);channel.queueDeclare("my fanout queue1",true,false,false,null);channel.queueBind("my fanout queue1","fanout exchange","");channel.basicConsume("my fanout queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my fanout queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my fanout queue2",true,false,false,null);channel.queueBind("my fanout queue2","fanout exchange","");channel1.basicConsume("my fanout queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my fanout queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class Publisher {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("fanout exchange", BuiltinExchangeType.FANOUT);channel.basicPublish("fanout exchange","", MessageProperties.PERSISTENT_TEXT_PLAIN,"fanout exchange消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

 队列需要同交换机绑定,生产者向交换机发送消息

Routing

消费者 

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class RoutingKeyConsumer {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("direct exchange", BuiltinExchangeType.DIRECT);channel.queueDeclare("my direct queue1",true,false,false,null);channel.queueBind("my direct queue1","direct exchange","info");channel.basicConsume("my direct queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my direct queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my direct queue2",true,false,false,null);channel.queueBind("my direct queue2","direct exchange","info");channel.queueBind("my direct queue2","direct exchange","error");channel1.basicConsume("my direct queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my direct queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class RoutingProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("direct exchange", BuiltinExchangeType.DIRECT);channel.basicPublish("direct exchange","info", MessageProperties.PERSISTENT_TEXT_PLAIN,"direct exchange info消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("direct exchange","error", MessageProperties.PERSISTENT_TEXT_PLAIN,"direct exchange error消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

Topics

交换机路由消息给队列时基于表达式,*匹配1个,#配置0个或1个或多个

例如:当队列1的路由值设置user.*,队列2的路由值设置user.#时,向交换机分别发送四条消息,消息的路由值分别为user.insert、user.insert.a、user.、user

此时队列1会收到路由值为user.insert和user.的消息,队列1能收到上面全部四条消息

消费者代码

package org.cc;import com.rabbitmq.client.*;
import org.junit.Test;import java.io.IOException;
import java.util.concurrent.TimeoutException;public class TopicsConsumer {@Testpublic void receive() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("topic exchange", BuiltinExchangeType.TOPIC);channel.queueDeclare("my topic queue1",true,false,false,null);channel.queueBind("my topic queue1","topic exchange","user.*");channel.basicConsume("my topic queue1",true,new DefaultConsumer(channel){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my topic queue1 consumer接收到消息:"+new String(body));}});Connection connection1 = ConnectionUtils.createConnection();Channel channel1 = connection1.createChannel();channel1.queueDeclare("my topic queue2",true,false,false,null);channel.queueBind("my topic queue2","topic exchange","user.#");channel1.basicConsume("my topic queue2",true,new DefaultConsumer(channel1){@Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {System.out.println("my topic queue2 consumer接收到消息:"+new String(body));}});System.in.read();//保持消费者一直监听队列}
}

生产者代码

package org.cc;import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import org.junit.Test;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;public class TopicsProducer {@Testpublic void sendMsg() throws IOException, TimeoutException {Connection connection = ConnectionUtils.createConnection();Channel channel = connection.createChannel();channel.exchangeDeclare("topic exchange", BuiltinExchangeType.TOPIC);channel.basicPublish("topic exchange","user.insert", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.insert消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user.insert.a", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.insert.a消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user.", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user.消息内容".getBytes(StandardCharsets.UTF_8));channel.basicPublish("topic exchange","user", MessageProperties.PERSISTENT_TEXT_PLAIN,"topic exchange user消息内容".getBytes(StandardCharsets.UTF_8));ConnectionUtils.closeConnection(connection,channel);}
}

模式具体使用(springboot集成rabbitmq)

使用idea构建项目,选择spring initializer,创建生产者项目springboot-rabbitmq-producer

  dependencies选择如下

 application.properties设置如下

 使用同样的方式创建消费者项目springboot-rabbitmq-consumer,将server.port设置为8081

当前springboot版本最新为2.6.3

HelloWorld

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.helloworld;import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-producer** @author v_choncheng* @description* @create 2022-02-15 14:42*/
@Component
@RabbitListener(queuesToDeclare = @Queue("helloworld"))
public class HelloWorldConsumer {@RabbitHandlerpublic void receive(String msg) {System.out.println("消费者接受到消息" + msg);}}

创建生产者

package com.example.springbootrabbitmqproducer.helloworld;import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** springboot-rabbitmq-producer** @author v_choncheng* @description* @create 2022-02-15 14:42*/
@Configuration
public class HelloWorldProducer {@Beanpublic Queue createQueue() {return new Queue("helloworld");}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者接收到一条消息


Work queues

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.workqueues;import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:11*/
@Component
public class WorkQueuesConsumer {@RabbitListener(queuesToDeclare = @Queue("workqueues"))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(queuesToDeclare = @Queue("workqueues"))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

运行此测试方法后可以看到消费者1、2轮流接收到消息


Publish/Subscribe

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.fanout;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:23*/
@Component
public class FanoutConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.FANOUT, name = "fanoutexchange"), value = @Queue("fanoutqueues1")))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.FANOUT, name = "fanoutexchange"), value = @Queue("fanoutqueues2")))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者1、2同时接收到消息


Routing

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.routing;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:38*/
@Component
public class RoutingConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.DIRECT, name = "routingexchange"), value = @Queue("routingqueues1"), key = {"debug", "verbose", "notice", "warning"}))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.DIRECT, name = "routingexchange"), value = @Queue("routingqueues2"), key = {"debug", "verbose"}))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者1接收四条消息、消费者2只接收到debug和verbose消息


Topics

创建消费者并启动消费者应用

package com.example.springbootrabbitmqconsumer.topics;import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;/*** springboot-rabbitmq-consumer** @author v_choncheng* @description* @create 2022-02-15 15:38*/
@Component
public class TopicsConsumer {@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicexchange"), value = @Queue("topicqueues1"), key = {"user.*"}))public void receive1(String msg) {System.out.println("消费者1接受到消息" + msg);}@RabbitListener(bindings = @QueueBinding(exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicexchange"), value = @Queue("topicqueues2"), key = {"user.#", "verbose"}))public void receive2(String msg) {System.out.println("消费者2接受到消息" + msg);}
}

生产者工程测试类中增加测试方法

 运行此测试方法后可以看到消费者2接收四条消息、消费者1只接收到user.和user.insert消息

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/530329.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql一直copying to tmp table_mysql提示Copying to tmp table on disk

网站运行的慢了&#xff0c;查找原因是Copying to tmp table on disk那怎么解决这个问题呢解决一例最近常常碰到网站慢的情况&#xff0c;登陆到后台&#xff0c;查询一下 /opt/mysql/bin/mysqladmin processlist;发现一个查询状态为&#xff1a; Copying to tmp table 而且此查…

idea cloud bootstrap是啥_application.yml与bootstrap.yml的区别

Spring Boot 默认支持 properties(.properties) 和 YAML(.yml .yaml ) 两种格式的配置文件&#xff0c;yml 和 properties 文件都属于配置文件&#xff0c;功能一样。Spring Cloud 构建于 Spring Boot 之上&#xff0c;在 Spring Boot 中有两种上下文&#xff0c;一种是 bootst…

元数据解决分表不可 mysql_MySQL InnoDB技术内幕:内存管理、事务和锁

前面有多篇文章介绍过MySQL InnoDB的相关知识&#xff0c;今天我们要更深入一些&#xff0c;看看它们的内部原理和机制是如何实现的。一、内存管理我们知道&#xff0c;MySQl是一个存储系统&#xff0c;数据最后都写在磁盘上。我们以前也提到过&#xff0c;磁盘的速度特别是大容…

navicat for mysql 13_Navicat for MySQL下载

Navicat for MySQL 是一套管理和开发 MySQL 或 MariaDB 的理想解决方案。它使你以单一程序同时连接到 MySQL 和 MariaDB。这个功能齐备的前端软件为数据库管理、开发和维护提供了直观而强大的图形界面。它提供了一组全面的工具给 MySQL 或MariaDB 新手&#xff0c;同时给专业人…

spring兼容mysql_springboot 最新版本支持 mysql6.0.6吗

缥缈止盈1.首先在pom文件中加入下列依赖,一个使用jpa所需依赖,一个连接MySQL使用的依赖:mysqlmysql-connector-javaorg.springframework.bootspring-boot-starter-data-jpa 123456789102.在配置文件中添加datasource配置和jpa配置,在mysql中已经提前创建了一个名为db_test的数据…

java虚拟机内存监控_java虚拟机内存监控工具jps,jinfo,Jstack,jstat,jmap,jhat使用...

将会打印出很多jvm运行时参数信息&#xff0c;由于比较长这里不再打印出来&#xff0c;可以自己试试&#xff0c;内容一目了然Jstack(Stack Trace for Java)&#xff1a;JVM堆栈跟踪工具jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息&#xff0c;如…

idea 调试java技巧_IDEA 调试Java代码的两个技巧

本文介绍两个使用IDEA 调试Java代码的两个技巧&#xff1a;修改变量值使用RuntimeException终止代码执行修改变量值在Java代码调试过程中&#xff0c;我们可以修改变量值&#xff0c;使其达到走指定分支的目的&#xff0c;或者使其满足某个条件。我们以给变量beanName赋值为例&…

java免检异常_java-异常

java提供了异常处理机制&#xff1a;程序运行受阻时候的处理方式。1、异常分类Error&#xff1a;系统错误&#xff0c;由java虚拟机抛出&#xff0c;很少发生&#xff1b;免检异常RuntimeException&#xff1a;程序设计错误&#xff0c;通常由java虚拟机抛出&#xff1b;免检异…

java编程需要数学知识吗_初学Java编程,需要英语和数学基础吗?

原标题&#xff1a;初学Java编程&#xff0c;需要英语和数学基础吗&#xff1f;“学习Java编程英语和数学是必备条件吗&#xff1f;”很多Java零基础学习或者转型IT行业的都会有这样的疑问&#xff0c;其实刚开始学习Java编程是不需要太高深的数学和英语基础的。刚开始学习Java…

java简单数据结构_图解Java常用数据结构

最近在整理数据结构方面的知识, 系统化看了下 Java 中常用数据结构, 突发奇想用动画来绘制数据流转过程.主要基于 jdk8, 可能会有些特性与 jdk7 之前不相同, 例如 LinkedList LinkedHashMap 中的双向列表不再是回环的.HashMap 中的单链表是尾插, 而不是头插入等等, 后文不再赘叙…

java const关键字_const关键字:终于拥有真正的常量声明语句

你好&#xff0c;今天大叔想和你唠扯唠扯 ES6 新增的关键字 —— const。在说 const 关键字之前&#xff0c;大叔先和你唠唠大叔自己对 const 的感受 —— JavaScript 尼玛终于可以声明真正的常量啦&#xff01;大叔为啥会发出这样滴感叹&#xff1f;实在是“天下苦秦久矣”呀~…

workerman高并发异步mysql_workerman怎么实现高并发

并发概念太模糊&#xff0c;这里以两种可以量化的指标并发连接数和并发请求数来说明。并发连接数是指服务器当前时刻一共维持了多少TCP连接&#xff0c;而这些连接上是否有数据通讯并不关注。 (推荐学习&#xff1a; workerman教程)例如一台消息推送服务器上可能维持了百万的设…

checkout 撤销修改_Git的4个阶段的撤销更改

虽然git诞生距今已有12年之久&#xff0c;网上各种关于git的介绍文章数不胜数&#xff0c;但是依然有很多人(包括我自己在内)对于它的功能不能完全掌握。以下的介绍只是基于我个人对于git的理解&#xff0c;并且可能生编硬造了一些不完全符合git说法的词语。目的只是为了让git通…

java访问权限最高_java 访问权限

Java语言中的访问权限修饰符有4种&#xff0c;但是仅有3个关键字&#xff0c;因为不写访问权限&#xff0c;在Java中被称为默认权限&#xff0c;或同包权限&#xff0c;本文中以(default)代替。下面按照权限从小到大的顺序对4中访问权限分别介绍。class我个人&#xff0c;我有很…

java中fork函数_java中的forkjoin框架的使用

fork join框架是java 7中引入框架&#xff0c;这个框架的引入主要是为了提升并行计算的能力。fork join主要有两个步骤&#xff0c;第一就是fork&#xff0c;将一个大任务分成很多个小任务&#xff0c;第二就是join&#xff0c;将第一个任务的结果join起来&#xff0c;生成最后…

java中已定义类型car_Java 8 习惯用语(8):Java 知道您的类型

Java™8是第一个支持类型推断的 Java 版本&#xff0c;而且它仅对 lambda 表达式支持此功能。在 lambda表达式中使用类型推断具有强大的作用&#xff0c;它将帮助您做好准备以应对未来的 Java版本&#xff0c;在今后的版本中还会将类型推断用于变量等更多可能。这里的诀窍在于恰…

java web 来源页_Java:Java Web--分页效果

先来看一看分页的实现原理万能公式.jpg项目目录.PNG首先,新建Java Web项目一. 梳理业务逻辑重定向到URL(跳转到StudentViewAction页面)//index.jsp页面1.从页面接收可变的值2.接收值有问题时,初始化为13.如果没有问题,把String类型接收值强转成Integer4.实例DAO方法,调用findSt…

java 浏览器 安全_安全策略-IE浏览器防黑十大秘籍

1.管理好Cookie在IE6.0中&#xff0c;打开“工具”→“Internet选项”→“隐私”对话框&#xff0c;这里设定了“阻止所有Cookie”、“高”、“中高”、“中”、“低”、“接受所有Cookie”六个级别&#xff0c;你只要拖动滑块就可以方便地进行设定&#xff0c;而点击下方的“编…

php截取指定字符串之后,php截取字符串(截取指定字符串之间的字符串)

一、PHP截取两个指定字符后边的字符$a "123abc#456";$b (strpos($a,""));$c (strpos($a,"#"));echo substr($a,$b1,$c-1);二、常用截取字符串技巧。//构造字符串$str "ABCDEFGHIJKLMNOPQRSTUVWXYZ";echo "原字符串&#xff1a;…

php 获取key的位置,PHP获取当前所在目录位置的方法

本文实例讲述了PHP获取当前所在目录位置的方法。分享给大家供大家参考。具体分析如下&#xff1a;如果要获取脚本文件的目录&#xff0c;要应用函数getcwd()来实现。函数声明如下&#xff1a;string getcwd ( void ) ;成功执行后返回当前目录字符串&#xff0c;失败返回FALSE。…