开发者

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

开发者 https://www.devze.com 2023-01-22 07:43 出处:网络
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?

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

精彩评论

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

关注公众号