S Thiyanesh

Ranch Hand
+ Follow
since Mar 19, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by S Thiyanesh

The hashCode() method implementation should make sure
1) to have same hash code value for identical objects(this is mandatory) and
2) try to have different hash code value for non-identical objects(though this is not mandatory).
By identical, i mean two objects having same state(identified by any key parameter in the object) and these two identical objects should have the same hashcode value. Still there is a possibility of non-identical objects having same hashCode() and its allowed legally.

hashCode() is useful in identifying the set of objects that fall under a common hash value.

Till now we are not worried about comparing two objects.

Now assume we have an object and we need to find whether the object exists in a collection.
Now we need to override the equals() method to define the identify the object. Only the set of objects that has the same hashcode value as that of the object under check will used for comparison in the equals method.
Out these objects that have the same hashcode value as the object under consideration, equal method helps in identifying the exact object.(based on the state of the object)

General rule is
1) equals() method should 100% determine whether two objects are equal(this could be two reference variables pointing to same object or two reference variables pointing to different object having the same state)
2) hashCode() method should make sure the similar objects always fall under the same bucket. (Still different objects can fall under the same bucket, but then number of comparisons made by equals method will increase. Hence we should strive to make unique hashcode value for different objects.)


Its a synchronization issue due to race condition.

Scenario in following sequence could have resulted in incorrect behavior.
1) Request from "A" for the key "A"(first thread)
2) Fetch the value for the key "A" and store in a variable.
3) Request from "B" for the key "B" (second thread)
4) Fetch the value for the key "B" and updates the same variable used to store the value of "A"
5) Return the value stored in the variable for the call for A(actual value is that of the "B")
6) Return the value stored in the variable for the call for B

If you have this logic, then you need to use synchronized.
The reason that "Exception" is allowed in the catch clause is "Any runtime exception is a subclass Exception" and we are handling the broader exception.
We are not allowed to catch "IOException" if none of the enclosing code block can cause "IOException", since no RuntimeException is subclass of the "IOException".

Thanks,
Thiyaneshwaran S
1) The implementation of hashCode() is not dependent on equals(). Only constraint is that it should be consistent.
2) The implementation of equals() is indirectly dependent on hashCode(), as the set of objects chosen for equals() method are selected from a single hashCode() bucket.

Thanks,
Thiyaneshwaran S
As per question, there seems to be some issue with application logic rather than thread sync.
1) If you are filling the map with static data for all the available values, and fetching the values for specific user, then it should not be dependent on the thread.
2) If there are user specific data to be dynamically loaded into the map for each request, then if you are using the same key, then the values will be overridden. If this is case, then you should change the way, the keys are mapped.

Please do post more about the problem if the issue is not clear.

Thanks
Thiyanesh
The order of comparison of the object members might be giving you a wrong ordering.
Please check it.



-Thiyaneshwaran S
13 years ago
Have you tried placing the values with in double quotes?(eg:<option value="sunday">Sunday</option>
Is this placed with in a form?
Since both the interface and abstract class have the same method and the Cricket class impements the method, what are things happening or the flow of control? Can you please give more about this?


Which method gets implemented in the main class?
Can you please give the flow of control also?
It means that for each new request, a thread is created with new request and response objects and these separate thread operate on the same instance of the servlet.
They meant to say that there is only one instance of the servlet with multiple threads operating on them. That is why you should be careful in using the instance variables in the servlet class.
With any final reference variable you can't assign the new object to the reference.
You can change the state of the object referenced.
Interface references can be casted and assigned to class references with the assumption that any of the subclass object inheriting the our interface in the same hierarchy might be stored in the interface reference.

But the final classes can't be further inherited.
So Until unless the interface is implemented anywhere in the hierarchy till our final class they can't casted to the final class reference.
A continue statement will always check the condition in loops and proceeds the next iteration.
In your example, the continue statement will not bypass the loop condition.

try


Hope this one does the purpose of printing only the values of i >= 5 and i <= 10
Only the instance method overriding takes the run-time polymorphism and depends on the object type.
All the other bindings are resolved at the compile time as per the reference type.