java深入
webservice远程服务api
soap协议:简单对象访问协议,基于http+xml的通信协议
服务端:使用axis2发布不需要配置可以把service类中所有的public方法发布成webservice,将Service.class文件放到Tomcat容器的webapps\axis2\WEB-INF\pojo目录中(如果没有pojo目录,则新建该目录)。默认是热发布使用@webservice注解
验证:在浏览器地址栏中输入如下的URL: http://localhost:8080/axis2/services/listServices
客户端:axis2同步调用webservice使用RPCServiceClient得到optionsetTo(指定调用url) ②设置要调用方法QName qname=new QName("http://ws.apache.org/axis2", method); ③调用远程方法,并指定方法参数以及返回值类型Object[] result=client.invokeBlocking(qname,params,classes)
client.Call远程调用 call = (Call)client.Service.createCall(); call.setTargetEndpointAddress(远程调用地址); call.setOperationName(远程调用方法); call.addParameter(参数名,参数类型:String,参数模式:'IN' or 'OUT') call.setReturnType(返回值类型:String);
远程调用call.invoke(new Object[] { 方法参数})
分布式相关
多系统之间通信:①通过httpclient提供的http服务功能进行页面访问 ②通过MQ服务器做做异步调用
单点登录实现:单点登录使用redis+cookie实现,将用户信息存入redis中,key作为用户凭证放在客户端cookie中,用户通过cookie的用户凭证判断是否登录。
cookie的安全性:凭证是使用统一工具类生成的唯一uuid,设置了cookie关闭了document.cookie的取值功能
cookie跨域问题:在二级系统使用共享cookie的将多个系统的域名统一作为二级域名,统一平台提供主域名。cookie.setpath("/")设置cookie路径为根路径,通过cookie.setDomain(。父域名)使得项目之间跨域访问她们的cookie
购物车:使用redis+cookie实现购物车。用户未登录将商品id保存的在redis未登录购物车中,拦截器拦截到用户登录时将数据合并到数据库中登录后的购物车,用过json解析商品id查到商品信息,购物车商品信息是可变的
高并发问题:①页面静态化,避免大量请求访问数据库 ②动静态分离图片静态资源服务器,保证系统消耗好执行效率 ③数据库集群根据业务模块分离 ④ 使用redis缓存减低数据库访问压力 ⑤使用nginx服务器做负载均衡,由nginx接受用户请求在分配服务器处理,实现方式:http重定向,dns配置,正反向代理
Zookeeper
zookeeper是一个分布式应用协调系统,用来完成统一命名服务、状态同步服务、集群管理、分布式应用配置管理等工作
常用的设计模式和应用
单例模式:提供唯一实例
public class singleton{ private singleton(){}; private static final Singleton sing = new Singleton(); //静态工厂方法 public static Singleton getInstance(){
return sing;
}
}
工厂模式: 创建对象需要大量的重复代码,实例不依赖与对象被创建和实现细节,由其子类指定实现
消息队列(ActiveMQ)
ActiveMQ:是一种应用程序对应用程序的通信方法,在高并发的情况来不及同步处理,请求往往会堵塞。通过消息队列我们可以异步处理消息,缓解系统压力,提高系统吞吐量,如用户注册发邮件和短信,登录增加积分等
优势:解耦、异步、高并发削峰
缺点:系统可用性降低、消息一致性问题如:消息重复消费,消息传输问题等
Linux基本命令 查看线程
find / -name filename.txt 根据名称查找/目录下的filename.txt文件
ps -ef|grep tomcat 查看所有有关tomcat的进程
kill -9 19979 杀死终止线程号19979的进程
ps aux|grep java 查看java进程
搭建缓存redis
redis存储类型(string,Hash,List,Set,zset)
web.xml
<!--mybatis和redis配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-redis.xml,classpath:spring-mybaties.xml</param-value>
</context-param>
spring-redis.xml
<context:property-placeholder location="classpath:*.properties"/>
<!--设置数据池-->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}"></property>
<property name="minIdle" value="${redis.minIdle}"></property>
<property name="maxTotal" value="${redis.maxTotal}"></property>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"></property>
<property name="testOnBorrow" value="${redis.testOnBorrow}"></property>
</bean>
<!--链接redis-->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}"></property>
<property name="port" value="${redis.port}"></property>
<property name="password" value="${redis.password}"></property>
<property name="poolConfig" ref="poolConfig"></property>
</bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="connectionFactory" >
<!--以下针对各种数据进行序列化方式的选择-->
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
nginx
高可用,反向代理,负载均衡,异步非阻塞高并发低内存的反响代理服务器
nginx处理请求
① nginx在启动时,会解析配置文件,得到需要监听的端口与ip地址,然后在nginx的master进程里面,先初始化好这个监控的socket,再进行listen然后再fork出多个子进程出来, 子进程会竞争accept新的连接。
② 客户端就可以向nginx发起连接了。当客户端与nginx进行三次握手,与nginx建立好一个连接后
③ 某一个子进程会accept成功,然后创建nginx对连接的封装,即ngx_connection_t结构体
④ 根据事件调用相应的事件处理模块,如http模块与客户端进行数据的交换。
⑤ nginx或客户端来主动关掉连接,到此,一个连接就寿终正寝了
Jquery和ajax
$()是jquery()的别称,$()用于将任何对象包裹成jQuery对象。jquery支持不通选择器,如id选择器$("#id"),类选择器$(".class"),标签选择器$("div")。
jquery提供事件$("#id").click(function(){$("#id1").hide()})。
$(dcument).ready(function(){xxxxxxxxxx}):跨浏览器文档进入ready状态执行代码,$(function({xxxxxxxxxxxx})。
javaScript windows.onLoad事件等待文档dom、图片、视频、音频等外部文件加载完后执行。$(document).ready()只需要等待dom文档加载就执行。
$("[name=nameOfSelectTag]:selected") 找到所有select选中项
each()函数jquery迭代器;
$("p a")找出p标签下所有的超链接;$("p >a")只找出p标签下的超链接不含p下其他标签的超链接;
$("this")返回jquery对象,如$("this").val(); this表示当前元素
$("a").each( function(){ alert($("this").attr("href")); }) 提取所有超链接;
attr(name , value) 设置属性值;
$.ajax({ url:"xxxxx" ,asnyc :false }); jquery实现ajax

浙公网安备 33010602011771号