• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using ThreadLocal for setting data in a WebApplication

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using ThreadLocal, that means data is local to thread, you can have thread-safety.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see no advantage to using thread-local storage. What problem are you trying to solve that requires this?
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage would be
data can be more secured know.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your nice explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic