很多地方都在说kryo是多么的有效率,多么的快.本人不幸遇到了大量的bug,到了不得不说的地步. 有采用kryo的团队请三思而后行,不然欲哭无泪
kryo版本是 kryo-3.0.3
class info implements Serializable{
private static final long serialVersionUID = -4914434736682797733L;
String id;
String name;
String password;
public info() {
// TODO Auto-generated constructor stub
}
public info(String id,String name,String password) {
// TODO Auto-generated constructor stub
this.id=id;
this.name=name;
this.password=password;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String select() {
return id+" "+name+" "+password;
}
public String getitem(String key) {
switch (key) {
case "name":
key=this.getName();
break;
case "id":
key=this.getId();
break;
case "password":
key=this.getPassword();
break;
default:
key=" the key is not here";
break;
}
return key;
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import org.objenesis.strategy.StdInstantiatorStrategy;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.KryoException;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
public class ttt {
public static void main(String []agrs) throws Exception {
Kryo kryo = new Kryo();
kryo.setReferences(false);
kryo.setRegistrationRequired(false);
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
kryo.register(wty.class); kryo.register(info.class);
kryo.register(HashMap.class);
Output output = new Output(new FileOutputStream("c:/file.bin"));
for (int i = 0; i < 20; i++) {
kryo.writeObject(output, new info("1","admin","888888"));
}
output.flush();
output.close();
long p=System.currentTimeMillis();
Input input = new Input(new FileInputStream(&#