Ryan Raina

+ Follow
since Jun 16, 2010
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ryan Raina

hi all

I have a doubt regarding using thread local variables.. consider the following code

My first question is I want thread local present in the same class where rest of the methods are also present(On browsing internet everybody is making it in separate class and making thread local object in it ).....i want it in the same class(is the usage correct??)
My top level is singleton ..do I have any issue because of it..Also if threadlocal is static will it have any issue

Thanks in advance

Ryan Raina wrote:

Hebert Coelho wrote:This posts talk about the problem and give 4 solutions: http://uaihebert.com/?p=1383

I am still not able to understand it ..only collection should be LAZY fetch but a simple property should be eager by default...

I think I have figured this out ..The problem is with load method which always returns a proxy whether for simple property or collection...But if one uses get method it eager fetches simple properties but still gives a proxy for all collections...
Also if ID is not found get will return null while as load will throw an exception..


Hebert Coelho wrote:This posts talk about the problem and give 4 solutions: http://uaihebert.com/?p=1383

I am still not able to understand it ..only collection should be LAZY fetch but a simple property should be eager by default...
Consider the following code

My main method


I am getting this exception on System.out.println(user2.getUserName())

It looks like session was closed that's why it happened
But isn't this applicable to the collections only...here I have a simple property which I am fetching which should be fetched eagerly by default

Thanks in advance
Hi All

Consider the following code

[Added code tags - see UseCodeTags for details]


A about to wait.
B about to wait.
A interrupted.
A terminating.
B interrupted.
B terminating.

my question is that do i need to have synchronized keyword here is the run method..It looks like I need that but I want to understand why??

I am calling run method on two different objects..so every object will have it's own method copy..so they should not block here...and every thread get's it's local thread copy..

Any suggestions??
Thanks Winston Gutkowski for your response

My purpose of viewing the source code to to understand the overall architecture of the collection API

I want to learn how to architect a web application from the scratch...so i thought java API might be a good learning...

I know most of the design patters and have used them also but the thing is that I want to understand how one should be able to design an web app from scratch..

Can you suggest some books or material that would help me going about this...I am a good programmer but designing is not my stuff...so kinda want to learn that part...

Anyways I thank you for your response ...specially for this

I'd also suggest that looking at foundation class source code may not be the best use of your time, because the whole point about object-orientation is to hide implementation - and whatever you do, NEVER write programs that rely on source code that you've looked at.

This was useful

11 years ago
Hello All

While seeing the source code of AbstractSequentialList it looks like it gives implementation of some of the methods ..I am not able to understand why??

Take a look at the declaration of LinkedList class

public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, java.io.Serializable

LinkedList will inherit all methods of collection,List,AbstractList,AbstractCollection and also AbstractSequentialList.....

It looks like LinkedList class overrides all the implemtations present in AbstractSequentialList...and also AbstractSequentialList is not used anywhere by any other class
Why does it give implemention or say why to have it in first place??

Also I saw same thing in case of AbstractList class ...All subclass whether ArrayList or AbstractSequentialList override the behaviour..
But this class has more to do with vector class which extends its methods and doesn't override it..so that fine..

What is your say on this guys??

Thanks for your help always

11 years ago
Thanks everyone for your replies
11 years ago
Hello every one

We all know that byte Variables can have values from -128 to +127 and occupy 1 byte (8 bits) in memory

so 0 1 1 1 1 1 1 1 => +127 as first digit is 0 which means +ive means max number represented by byte

but what should be the least number..byte defination says it can be -128..I am not able to understand that part

so 128 means

1 0 0 0 0 0 0 0

but here first 1 is used to detemine the sign

In my view least number should be -127 because

1 0 0 0 0 0 0 1 which means -127(2'complement of 127) where first (right most) will deal only with sign and rest is value.

but if somebody will include -128 where can we store the sign of the number in this case as rightmost bit is part of the number and we can only have 8 bit representation
Also 2' complement of 128 and -128 is same.

so 128=>1 0 0 0 0 0 0 0
-128=>2's complement of 128=>1 0 0 0 0 0 0 0

so for -128 sign bit will be missing

Thanks in advance
11 years ago
Hello everybody

I have a scenario where there is an object let's say context which needs to be passed from threadA to the the other thread say threadB..
As soon as the object is passed to threadB ...threadA returns back and starts making changes to context object ..but it might happen
that threadB hasn't done it work so the value of context would have been changed..there is a problem

My question is how can we deal with this..

One scenario I can think of passing is that I would pass a cloned object of the context rather than the context itself to the ThreadB..
But let's assume it's not a option..

Also how would syncronisation work here....I can get a lock on the context itself but it still doesn't solve the problem
because it might happen threadA will get the lock and modify the context object..

Thanks in advance.....
Thanks for you help !!!
hello friends please see the code below..Here I am using executors for multi-threading....

My problem is that I am acquiring lock on the list so that in consumer thread only one thread should be allowed to remove the element from list...but it has a drawback I cannot add an item in same list in producer as it might happen that list lock in taken by one of the consumer thread...
so I want that producer should be able to add in the list but only one consumer should be able to remove from it.. any suggestions...please note that there are 3 consumer threads and 1 producer thread

[Added code tags - see UseCodeTags for details]
We have a requirement that image file can contain spaces in between them...I do support multiple platforms ...Could you suggest something...
12 years ago
Hi all

I want that my file should contain spaces
for example metlife newone.jif

Consider the following code

Here the output will be metlife
But I want it to be metlife newone.gif
If I remove space in between the image name..Output comes to be metlifenewone.gif...which is correct..

I guess I have to modify regex.Could anybody shed light on it..

Thanks in advance

[Edit - added code tags - MB]
12 years ago
thanks all for replies..
I am doing is a url deployment...My app server is Jboss5.1.0 ga...I have edited profile.xml and i have given the url to the deployed artifact.....war is generated by the installer while installing the product on the customer side......It's already in exploded form ......That's the reason I wanted to know about this....
12 years ago