Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 04:41 PM
Member
 
Join Date: May 2008
Posts: 4
sajdutt is on a distinguished road
Object Comparison!
Ok guys,

I have a problem and I don't know what causes it.

In one of the classes, I used a statement like:

if(a.getClientId() == b.getClientId()){...}

getClientId returns ID object which implements Comparable, Cloneable, Serializable.

This returns true when I run it from my local resin server. Now, if I link my server to another server by means of synchronization, the above statement returns false. Of course, if I used "equals" instead of "==", there would have been no problem. ..and I know the rules of Object comparison. My question is if the above statement works in a standalone server, then why it doesn't when the two servers are synced? Again, using "equals" solves my problem but that's not what I wanna know. Any idea?


How it is synced:

I have two machines (Apple and Orange). Both using resin servers.

I modified a portion of my web.xml:

Apple's web.xml file:

<init-param Apple-peer='Apple Orange'/> <!-- Before it was:<init-param Apple-peer='Apple'/> -->
<init-param Apple-db='Apple/SERVER'/>
<init-param Apple-db-connections='5'/>

Orange's web.xml file:

<init-param Orange-peer='Orange Apple'/> <!-- Before it was:<init-param Orange-peer='Orange'/> -->
<init-param Orange-db='Orange/SERVER'/>
<init-param Orange-db-connections='5'/>

Now, two machines have to be started simultaneously, otherwise, one will wait for the other one to start.

Thank a lot in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-21-2008, 08:06 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 524
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
take a look at this thread..
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-22-2008, 06:08 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
Don't use == unless you really want to compare pointer values. Implement and use .equals().
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-22-2008, 06:30 AM
Member
 
Join Date: May 2008
Posts: 1
tbondcom8 is on a distinguished road
I need it
It is Just what I need,you can go to 翻译公司 to search for better.
__________________
Good
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-22-2008, 06:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,970
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Hi tbondcom8,

Please don't put links here other than on English. Our community based on English and most of the people can't read your posts. Please pay attention on this.

__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-22-2008, 11:37 AM
Member
 
Join Date: May 2008
Posts: 4
sajdutt is on a distinguished road
I know it very well when to use "==" and when to use "equals". I know what JVM does before creating a new object. The Heap and all. That's not what I am looking for as an answer.

It works when the servers are not synced. How come?

Last edited by sajdutt : 05-22-2008 at 11:41 AM.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-22-2008, 04:36 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
How can I answer your question without looking at the code that created the ID instances? Maybe when the servers are not synced the IDs are reused when they mean the same thing. Maybe when you sync your servers one of the instances (or both) of ID come from a communication layer where objects are instantiated every time you sync something (do you use RMI to send parameters across?). No matter what the cause of == working is in the end it is just plain wrong to use it. If you want non generic answers show more code.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-23-2008, 02:48 PM
Member
 
Join Date: May 2008
Posts: 4
sajdutt is on a distinguished road
Thanks for your replies Daniel.

It's just that the coding for adding the user and the comparison process involves several Java classes and JSP pages. Let me go through the steps.

It's a huge Financial System where you can add a Trader (a new user), include him with other employees who belong to the same company who are already registered in the system.

When you add an user, the JSP calls a certain Java class (Cache.java) to do that which also involves other java classes to complete the task. Cache class assigns the id (an object - ID class) of the company to the newly created user.

When we make a Trade (A contract between two traders), we search for his colleagues( Other traders/brokers from his company).

//Get the cache
ICache cache = (ICache) session.getAttribute("cache");

//Get the newly created trader
IUser trader = cache.getUser(userName);

//get the colleagues. It's in a loop of Traders
IUser ccUser = (IUser) cache.getUser((ID) iter.next());

//Compare the traders to see if they belong to the same company
if (toIncludeUser.getClientId() == mainUser.getClientId()) {...}

The comparison above returns true when the Trader is not a newly created trader. And also it returns true when servers are not synced. Moreover, it returns true if the server is the elected server.

Elected Server: When multiple servers are synced, Cache checks what server is elected. The election is done randomly. When we add a new user, we first add that user in the elected server. Then we add it in the other servers.

Last edited by sajdutt : 05-23-2008 at 02:54 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
String comparison abhiN New To Java 2 04-09-2008 05:47 AM
Comparison of Strings Cero.Uno New To Java 3 02-11-2008 03:46 AM
Date comparison Rageagainst20 New To Java 0 12-19-2007 07:34 PM
Parsing Dates for Comparison Rageagainst20 New To Java 1 12-19-2007 06:50 AM
String comparison sireesha New To Java 1 12-18-2007 01:16 AM


All times are GMT +3. The time now is 07:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org