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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:06:20+00:00 2026-06-06T09:06:20+00:00

Imagine two simple java applications. Both of them are implementing the same JAR file

  • 0

Imagine two simple java applications.
Both of them are implementing the same JAR file containting an enum file like this:

enum enum1{
   value1;
}

In both the applications I print the enum1.value1´s hashcode.

System.out.print(enum1.value1.hashCode());

How does the JVM work since the hashcodes are not equal even if the JAR file that the two applications implement is the same?

Why are not the hashcodes equal since it is the same JAR file the both applications implement?

EDIT
I have two applications that access a database. They are run within the same JVM. I would like to implement a locking mechanism so that when application 1 is writing to the database, application 2 has to wait for its turn (that is when the lock has been released by application 1). My solution is, if possible, to make an interface that has some ReentrantLocks declared or an enum that should act as lock and is used by the two applications. But then the instance of the interface/enum should be equal in both the applications, because you can only synchronize the same object.

EDIT 2
This is the architecture:

App1.jar              Commons.jar         App2.jar
App1Main.class        Commons.class       App2Main.class 

Both App1 and App2 includes Commons.jar. The commons.class is just a simple singleton class.
In both App1 and App2 I print the commons instance hashcode:

System.out.println(Commons.getInstance().hashCode());

Both java applications are run like “java -jar app1” and “java -jar app2” so there are two processes when they are running.

But they print different hashcodes and that is, what I belive (correct me if I am wrong), because they have been loaded by different class loaders. But the mystic arrives when I print the classloader in both apps:

System.out.print(ClassLoader.getSystemClassLoader().hashCode());

Then the hashcode is equal in both applications.

  • 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-06T09:06:22+00:00Added an answer on June 6, 2026 at 9:06 am

    It’s not clear whether you’re talking about two applications within the same process or not. Even if you are, if those two applications have separate ClassLoader instances loading the same jar file, the two enum types are different types as far as the JVM is concerned. If you want a single type within a process used by two applications, it has to be loaded by a single classloader.

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

Sidebar

Related Questions

let's imagine that i have a simple table like this: id - record id
I imagine two, but I would like to confirm if I am making sense
I'm going crazy with this and would greatly appreciate some help. Imagine two tables
Let's imagine really simple game... We have a labirinth and two players trying to
Hello (please excuse me for my ugly english :p), Imagine these two simple models
Imagine the following two entities. Element is simple class containing some data: @Entity public
I imagine the solution to this is very simple, and apologize in advance if
I imagine this is fairly simple and one I should be able to get
I am new to AX, so it could be a simple question. Imagine two
I am drawing two relative simple shapes and the geometry of them do not

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.