什么是构造代码块
只听过静态代码块,是在程序运行的过程中,加载到类 的数据里
构造代码块
运行在构造方法前面执行,如果没有构造方法,但是被Componet修饰的话,就再bean生成之前先执行
看样例
@Component
@Slf4j
public class PrepareNode implements Node<UmpAlarmModel> {
private Map<String,String> metricMapping;
{
metricMapping = Maps.newConcurrentMap();
metricMapping.put("tp50","method.tp50");
metricMapping.put("tp90","method.tp90");
metricMapping.put("tp99","method.tp99");
metricMapping.put("tp999","method.tp999");
metricMapping.put("availableRate","method.availrate");
metricMapping.put("invokeCount","method.count.total");
metricMapping.put("max","method.max");
metricMapping.put("avg","method.avg");
metricMapping.put("min","method.min");
}
}
标签:构造方法,代码,metricMapping,构造,put,method
From: https://www.cnblogs.com/PythonOrg/p/17332438.html