This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

control the concurent users

 
thinakaran thinakaran
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to control the concurent users?
Suppose i have 4 users in my pool. But i want at a time only one user should acess.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pesky concurrent users. I recommend shock collars, that should keep them in line.
Seriously though - well, this is what synchronization is about. Read up on threads and synchronization if you haven't. You generally need to understand threads fairly well in order to get synchronization to work correctly and efficiently, so it's worth your time to study now if you're uncertain about some of the concepts. Then, identify which parts of your code you need to prevent users from accessing concurrently. Protect those sections of code by putting some sort of synchronized block around them, or declaring the method synchronized.
Pay attention to what monitor object is being used by each synchonized section - if you want one section of code to block another until it's done, they must both be synchronized on the same monitor. For simplicity, you probably want all synchonized code to sync on a single server object instance. But it's difficult to say more without knowing more about your design.
Beware also that the more code you synchronize, the slower your code will be for the majority of users. So try to only synchronize the parts that need to be synchonized. On the other hand, if you fail to sync something shat should be synced, you'l probably get really strange and unreporducible beahvior, very difficult to debug. I'd rather have slow code that works correctly than fast code that sometimes blows up, so when in doubt, synchronize. Then study some more until you're no longer in doubt.
[ March 29, 2003: Message edited by: Jim Yingst ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic