开发者

How to identify objects to be set serializable for server clustering?

I understand that if we want to setup clustering between servers.

Is there any systematic way to check i开发者_Go百科f any objects are not serilizable?

Because currently we use functionality testing to check if got any exception encountered related to serialization

Thanks


use instanceof operator,
you can check that whether the particular object is of particular type


As per org.life.java first check whether a class implements serializable interface using instanceof keyword

if (obj instanceof Serializable)

The above is just a check, then you have to check whether all the member variables of this class is serializable.for example consider you have an person object as the member variables ,but if that class does not implement serializable then your program fails.

Better you write a method that throws exception when it is not serializable. Use ByteOutputStream and write to the file.

public void testIsSerializable() 
   throws SerilizableException, IOException {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(path);
    oos.close();

    }

Write a try block

try
{
testIsSerializable();
}
catch (Exception e)
{
S.O.P("Cant serialize");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜