• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using ThreadLocal

 
Sameer Amte
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone used ThreadLocal for the assignment.
In a recent article, I have read that ThreadLocal is more scaleable than using synchronization.
The other advantage is that it would provide in-built client tracking i.e., tracking and allowing only those clients to unlock records which they have booked.
Can anyone shed any light on this.

Thanks
Sameer
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use RMI, there's no guarantee that a single client will be associated with a single thread. It's quite possible that two method calls from the same client will be handled by different threads. So this technique is useless if you're using RMI.
If you use sockets, and make sure that there's one thread for each socket - well, this might be useful then; I haven't thought about it much. What data would you be using the ThreadLocal for? I strongly suspect that some parts of the system will still require synchronization rather than ThreadLocal, as you ultimately need to share data between threads. If client 1 locks a record, client 2 needs to be able to detect that the record is locked. And if client 1 updates and unlocks the record, client 2 should then be able to see the updated data. So I'm not sure how useful it is to have some data in a ThreadLocal - ultimately it needs to be shared with other threads.
Note also that scalability isn't really a requirement for the assignment. It's nice if you can get a nice efficient design, but don't sacrifice simplicity. I'm not saying it's not possible to have a reasonably simple solution with Sockets and ThreadLocal, but offhand it sounds more complex to me, which is why I haven't thought much about it. And personally I'm not going to switch over to using sockets at this point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic