Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7892353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:50:55+00:00 2026-06-03T06:50:55+00:00

Question says everything. Is there any special event occurs? I have a class which

  • 0

Question says everything. Is there any special event occurs? I have a class which needs to implement Serializable interface. I am developing an application using Wicket. I have implemented a Factory class which will provide some links (to remove the redundancy of same code block written over and over):

public class NavigationLinkFactory implements Serializable {

    private static final long serialVersionUID = 7836960726965363785L;

    private NavigationLinkFactory() {

    }

    private static class SingletonHolder { 
        public static final NavigationLinkFactory instance = new NavigationLinkFactory();
    }

    public static NavigationLinkFactory getFactory() {          
        return SingletonHolder.instance;

    }

    private Object readResolve() throws ObjectStreamException {
        return SingletonHolder.instance;
    }

    public Link<Serializable> getUserHomeLink() {
        return new Link<Serializable>("home", new Model<Serializable>()) {

            private static final long serialVersionUID = -8282608926361995521L;

            @Override
            public void onClick() {
                EMSSession session = (EMSSession) getSession();
                session.setActiveHorizonalMenu(1);
                setResponsePage(HomePage.class);
            }
        };      
    }

    public Link<Serializable> getProfileLink() {
        return getProfileViewLink();
    }

    public Link<Serializable> getProfileViewLink() {
        return new Link<Serializable>("profileView", new Model<Serializable>()) {

            private static final long serialVersionUID = 232185489384306999L;

            @Override
            public void onClick() {
                EMSSession session = (EMSSession) getSession();
                session.setActiveHorizonalMenu(2);
                setResponsePage(ProfileViewPage.class);
            }
        };  
    }
}

If I doesn’t implement Serializable then I am getting exception at java.io.ObjectOutputStream.writeObject, which is thrown by the runtime environment of the wicket framework. If I implement it then it is gone.

So what really happens when one calls ObjectInputStream#readobject() method for some object created by Singleton pattern?

I am not adding wicket tag because I don’t think this question is related to the Wicket.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:50:56+00:00Added an answer on June 3, 2026 at 6:50 am

    Unfortunately, what happens by default is you get a second (or third, or thirty-seventh) instance of your singleton — not good. Luckily there’s a way around this: by implementing the readResolve() method, which can return a replacement object — the proper singleton object, in your case — instead of the one returned by default serialization. The link describes the particulars, but it’s pretty simple — you just implement this parameterless instance method to return the singleton object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question says it all basically. I want in a class MyClass to listen
The question says it all. I can't seem to find any recent rails tutorials
The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
Question says it all, really. My application is a time tracker. It's currently written
Question says it all, I've got a 500,000 line file that gets generated as
Question says it all. I tried browsing through the latest tag but could not
Question says it all. Some quick code examples of usage would be nice.. thanks!
Question says it all. Does anyone know if the following... size_t div(size_t value) {
As question says, How do I create such an app ? How do I
The question says it all. Inter Explorer's lack of standard compliance has struck, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.