jvm:
java拦击回收机制判断对象是否可以回收的依据:通过可达性分析算法(之前可能通过计数算法),查看手否有对象引用,以gc roots为起点,形成发散式的链表,如果没有任何一个对象与其有连接关系,则判定可以回收。
java新创建的对象一般放在伊甸区(大型对象直接放在老年区),伊甸区容量full以后执行gc,将存活的对象放到幸存者一区(幸存者共有两个区 任何时候都会保证其中一个为空),新生代每发生一次gc 幸存者区的对象age+1 默认age达到15会放到老年区(参数可配置)。
volatile关键字:
volatile关键字可以保证线程安全问题,被修饰的对象在多线程环境下对其他的线程可见。
原理:被volatile修饰的对象,被存储在主内存中,对象的任意的修改都会直接修改主内存,在多线程环境下,每个线程都在自己的内存中运行,对象都是从主内存中copy,所以没有被volatile修饰的对象不能保证线程安全,而被volatile修饰的对象都是直接从主内存中实时取出,所以线程安全。且volatile比synschonized效率更高,避免了上文文之间的切换
而内部迭代意味着改由Java类库来进行迭代,而不是客户代码。例如:
for(Object o: list) { // 外部迭代
System.out.println(o);
}
可以写成:
list.forEach(o -> {System.out.println(o);}); //forEach函数实现内部迭代
http://www.cnblogs.com/tiantianbyconan/p/3613506.html
DUBBO配置:http://blog.csdn.net/yerenyuan_pku/article/details/72758639
<dubbo:service interface=“com.xxx.XxxService” ref=“xxxService” version=“1.0” /> //提供者
<dubbo:reference id=“xxxService” interface=“com.xxx.XxxService” version=“1.0”/> //消费者
springboot 打jar包不需要在pom.xml配置tomcat
war包启动类要继承SpringBootServletInitializer并添加tomcat配置
insert ignore into insert into replace into
,springboot默认按照包顺序注入,所以在创建controller时service还没有注入
如果不用Dubbo,单一工程中spring的配置可能如下:
<bean id="xxxService" class="com.xxx.XxxServiceImpl" />
<bean id="xxxAction" class="com.xxx.XxxAction">
<property name="xxxService" ref="xxxService" />
</bean>
1
2
3
4
一旦用了Dubbo,在本地服务的基础上,只需做简单配置,即可完成远程化服务。
例如,将上面的配置文件拆分成两份,将服务定义部分放在服务提供方remote-provider.xml,
将服务引用部分放在服务消费方remote-consumer.xml,并在提供方增加暴露服务配置<dubbo:service>,
在消费方增加引用服务配置<dubbo:reference>。
可达性分析算法 GC root
引用计数算法
https://blog.csdn.net/qq_22215879/article/details/78136250
//复合索引匹配规则
CREATE TABLE `student` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) DEFAULT NULL,
`cid` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `name_cid_INX` (`name`,`cid`),
KEY `name_INX` (`name`)
) ENGINE=INNODB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
EXPLAIN SELECT * FROM student WHERE NAME='小红';
EXPLAIN SELECT * FROM student WHERE cid=1;
EXPLAIN SELECT * FROM student WHERE cid=1 AND NAME='小红';
最左匹配原则 1会用到索引 type为ref 效率相对较高
3也会用到索引 type为ref效率较高 因为用到了最左字段 name
通过1与3对比发现 最左匹配原则并不是where后第一个条件一定是索引的第一列 只要where后用到了索引第一列就会用到索引
指定日期 :tm_naga_calc_cfg
自动分区配置 :ts_table_partition_cfg
@Service("userService")
public class UserService {
public int count() {
return 10;
}
public int max(int size) {
int count = count();
return count > size ? count : size;
}
}
/**
* 调用容器的一个bean的方法,且传入一个配置项的值作为参数
*/
@Value("#{userService.max(${app.size})}") //max为userService类在容器中注入的名字 max是userService类的方法
private int max;
ApplicationContextAware接口:
重写setApplicationContext
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
SpringContextHolder.applicationContext = applicationContext;
}
public static <T> T getBean(Class<T> requiredType) {
assertContextInjected();
return applicationContext.getBean(requiredType);
}
可以通过getBean获取bean实例
InitializingBean接口 实现该接口 容器启动时初始化bean
BeanFactoryAware接口 实现本接口 容器启动时调用 setBeanFactory()可以通过getBean获取bean实例
public void setBeanFactory(BeanFactory beanFactory)
throws BeansException {
logger.debug("**************BeanFactory init begin,beanFactory:"+beanFactory);
BeanHelper.beanFactory=beanFactory;
}
public static<T> T getBean(Class<T> class1){
return beanFactory.getBean(class1);
}
http接口调用
public static String doPost(String url, String key,String jsonData) throws RuntimeException{
String receive = null;
PostMethod method = null;
HttpClient httpClient = null;
try {
SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
connectionManager.closeIdleConnections(60 * 1000);
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(true);
params.setMaxTotalConnections(1);
params.setConnectionTimeout(6 * 1000);
params.setSoTimeout(30 * 1000);
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
method = new PostMethod(url);
method.setParameter(key, jsonData);
int rspCode = httpClient.executeMethod(method);
log.info("====>rspCode:" + rspCode);
if(404 == rspCode)
throw new RuntimeException("404:str!");
if(500 == rspCode )
throw new RuntimeException("500:str!");
if(503 == rspCode )
throw new RuntimeException("503:str!");
receive = method.getResponseBodyAsString();
return receive;
} catch (Exception e) {
log.error("call car service error:",e);
throw new RuntimeException("str-"+e.getMessage());
} finally {
if(method!=null)
method.releaseConnection();
}
}