|
|
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.
|
|

05-21-2008, 04:41 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 4
|
|
|
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.
|
|

05-21-2008, 08:06 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 524
|
|
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.
|
|

05-22-2008, 06:08 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 183
|
|
|
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
|
|

05-22-2008, 06:30 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 1
|
|
|
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.
|
|

05-22-2008, 06:49 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,970
|
|
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.
|
|

05-22-2008, 11:37 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 4
|
|
|
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.
|
|

05-22-2008, 04:36 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 183
|
|
|
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
|
|

05-23-2008, 02:48 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 4
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|