File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Using ThreadLocal for setting data in a WebApplication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using ThreadLocal for setting data in a WebApplication" Watch "Using ThreadLocal for setting data in a WebApplication" New topic
Author

Using ThreadLocal for setting data in a WebApplication

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Hello ,

I had purposely posted this question in Servlets ,as i want to map it to the Web Environment.

What advantage i can get setting the data in a ThreadLocal . AS per docs this says that the data can be extracted by only a particular Thread . Please tell me how this is possible ??

and how this is different from setting it in a session/request.


Thanks in advance.


If you want something you never had do something which you had never done
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Using ThreadLocal, that means data is local to thread, you can have thread-safety.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks for the response .

Can you please provide me an example where this would be suitable (Setting the data for a Thread )

Thanks in advance .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

I see no advantage to using thread-local storage. What problem are you trying to solve that requires this?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
The advantage would be
data can be more secured know.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

RaviNada Kiran wrote:The advantage would be
data can be more secured know.

I have no idea what you mean by this.
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Container allocates each request in a web application with a new thread, creating one or selecting one available from thread pool.

So it doesn't makes any sense to store the data into ThreadLocal wrt web application.

Advantages, I dont feel wrt web app.




RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks a lot for your nice explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using ThreadLocal for setting data in a WebApplication