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 7750795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:22:57+00:00 2026-06-01T11:22:57+00:00

We keep reading about how to use ‘readResolve()’ to ensure singleness in case of

  • 0

We keep reading about how to use ‘readResolve()’ to ensure singleness in case of serializing a Singleton. But what are practical use cases for wanting to serialize a Singleton in the first place?

EDIT: pl. note: the question is about why to serialize a Singleton, and not about what’s a safe way to do so.

  • 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-01T11:22:59+00:00Added an answer on June 1, 2026 at 11:22 am

    The object may be a singleton, but it may be part of a larger structure which doesn’t quite know it is. For example, it may implement an interface which can have several different implementations (and thus, instances):

    interface StringSink extends Serializable { void dump(String s); }
    
    class MultiDumper implements Serializable {
        private final StringSink sink;
        public MultiDumper(StringSink sink){ this.sink = sink; }
        void doSomeStuff(Collection<String> strings){
            for (String s : strings) sink.dump(s);
        }
    }
    

    Now, let’s say we want a StringSink which dumps strings to stdout. Since there’s only one stdout, we might as well make it a singleton:

    /** Beware: Not good for serializing! */
    class StdoutStringSink {
        public static final StdoutStringSink INSTANCE = new StdoutStringSink();
        private StdoutStringSink(){}
        @Override
        public void dump(String s){ System.out.println(s); }
    }
    

    And we use it like this:

    MultiDumper dumper = new MultiDumper(StdoutStringSink.INSTANCE);
    

    If you were to serialize, and then deserialize this dumper, you’d have two StdoutStringSink instances floating around in your program.

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

Sidebar

Related Questions

I keep reading and reading about stacks but still I do not know how
I keep reading about C99 and C++11 and all these totally sweet things that
I keep reading about people who are test infected, meaning that they don't just
I keep reading about how great this new Canvas element for HTML5 is and
You'd think it would be easy, but keep reading. I can change many of
I mostly use Java and generics are relatively new. I keep reading that Java
I keep reading about the Backbone.js zombie (or memory leak) problem. Basically you have
I keep reading that, in C, using pointer arithmetic is generally faster than subscripting
I keep reading how everyone states to return a XmlDocument when you want to
I used the XMLReader format: XmlReader xmlReader = XmlReader.Create(batch.xml); while (xmlReader.Read()) { //Keep reading

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.