我有两台服务器(linode 3072 vps),一台(较旧)有 ubuntu 11.04 + Mysql 5.5.32,另一台(较新)有 centos 6.2。+ MySQL 5.5.36。My.cnf 文件也相同。但是,当我在同一个数据库上运行相同的查询(直接导出/导入)时,我从两台服务器获得了 2 个不同的响应时间和执行路径。
较老的人,反应较快。
1 SIMPLE ch ref PRIMARY,channel_name channel_name 122 const 1 Using where; Using temporary; Using filesort
1 SIMPLE t ref PRIMARY,channel_id channel_id 4 bcc.ch.channel_id 1554
1 SIMPLE p ref PRIMARY PRIMARY 4 bcc.t.entry_id 1 Using index
1 SIMPLE c eq_ref PRIMARY,group_id PRIMARY 4 bcc.p.cat_id 1 Using where
Run Code Online (Sandbox Code Playgroud)
较新的响应速度较慢。
1 SIMPLE ch ref PRIMARY,channel_name channel_name 122 const 1 Using where; Using temporary; Using filesort
1 SIMPLE …Run Code Online (Sandbox Code Playgroud) 我有一个类库,我没有写,它定义了几个类和子类,它们都有静态方法.一个非常简单的例子:
public class Vehicle {
static String getName() { return "unknown"; }
}
public class Car extends Vehicle {
static String getName() { return "car"; }
}
public class Train extends Vehicle {
static String getName() { return "train"; }
}
Run Code Online (Sandbox Code Playgroud)
现在,我有一个对象,它是一个Vehicle,可能是Car或Train,并且想要调用它的getName()函数.再次,非常简单:
public class SMCTest {
public static void main(String[] args) {
Vehicle vehicle=new Car();
System.out.println(vehicle.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
这打印"未知",而不是"汽车",因为JVM不需要或使用该对象来调用静态方法,它只使用该类.
如果这是我的代码,我会重写车辆库以使用单例和非静态方法,但因为它不是我的代码,我宁愿不触摸它.
有没有办法调用对象的"真实"类的静态方法,最好不使用反射?如果它有帮助,我可以vehicle将上面的例子改为Class <? extends Vehicle>变量并使用它,但我不知道这有助于我避免反射.