Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

Why we need implement Serializable for classes put in server when create a java web


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I assume we are talking about web apps built on Jakarta Servlet technology.

Your web app takes up memory on the web container at runtime. The more simultaneous users, the more memory is taken. To alleviate pressure on memory, some web containers invoke a feature whereby the less-active user sessions are written out to disk.

Also, some web containers do this when shutting down. Current sessions still running at shutdown are saved to disk, and automatically reconstituted when the server launches again.

Yet another scenario is load-balancing where multiple web containers working in tandem may relocate some sessions from any over-burdened server to any underutilized server. This transfer occurs on-the-fly during runtime.

In all these cases, the objects of your web app classes must support Serializable so that they may be written to storage or communicated over the local network.

In some complicated apps, making all your objects serializable may not be feasible. In that case you may choose to disable those three features I discussed above. Then you would make sure to run your web app on a deployment server that has more than enough cores and more than enough memory to handle the peak number of users your web app will encounter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...