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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:49:11+00:00 2026-06-11T19:49:11+00:00

I work with the OpenSource OODB db4o and my serialized classes inherit from a

  • 0

I work with the OpenSource OODB db4o and my serialized classes inherit from a common abstract.class which have two fields :

. . .
private final Long timeCreate = (System.currentTimeMillis() << 20) + (System.nanoTime() & 0xfffff);
private final int hashCode = timeCreate.hashCode();
. . . 
@Override
public final int hashCode() {
    return hashCode;
}
. . .

Is it a good practice to so?

The benchmarks I’ve tried give faster responses, but is a pitfall nested some where?

  • 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-11T19:49:12+00:00Added an answer on June 11, 2026 at 7:49 pm

    Ideally a hashCode of an object shouldn’t change in any case. One option is to only generate it on demand but in your case you have the problem that the timeCreate is not sure to be unique or monotonically increasing. System.nanoTime() can produce the same value over 1000 times if you only have micro-second resolution.

    private static final AtomicLong TIME_ID = new AtomicLong(0);
    private static long generateTimeId() {
        long now = System.currentTimeMillis() * 1000000;
        long id = TIME_ID.getAndIncrement();
        if (id > now)
            return id;
        TIME_ID.compareAndSet(id+1, now);
        return TIME_ID.getAndIncrement();
    }
    
    // produce a monotonically increasing time id.
    private final long timeCreate = generateTimeId();
    private final int hashCode = (int)((timeCreate >> 32) ^ timeCreate);
    

    Note: if two objects are equals == true, they must have the same hashCode.

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

Sidebar

Related Questions

Work on C# Desktop project,I have an account on paypal ,From my desktop application
I have the following file from the PARSEC opensource benchmarks, and I want to
i have this opensource code which is used to echo back response to web-socket
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
Work on this small test application to learn threading/locking. I have the following code,
well I have been trying to get Nivo Slider to work almost all day.
so I added all the jars from jMock 2.5.1 While attempting to follow http://www.ibm.com/developerworks/opensource/library/os-eclipse-rmock/index.html
I'm working with a task specific .NET plattform, which is precompiled and not OpenSource.
I'm triing to get soap to work in qt i found: qtsoap-2.7_1-opensource my request
I currently have a PrintingWebService that I call from an AJAX page with all

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.