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

control the concurent users

thinakaran thinakaran
Greenhorn

Joined: Mar 28, 2003
Posts: 8
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

Joined: Jan 30, 2000
Posts: 18671
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'm not back." - Bill Harding, Twister
 
jQuery in Action, 2nd edition
 
subject: control the concurent users