-
Junior Member
Is it possible for the developer to apply Synchronization
Is it possible for the developer to apply Synchronization / Obtain a lock on an object while developing J2EE application? Some where I read that containers (Both web container and Enterpise Bean Container) would take care of Thread safety and developer should not bother about this? But don't we apply Synchronization on methods say for instance in a sessionBean which is actually acting on a Account Entity bean?
-
Contributing Member
Re: Is it possible for the developer to apply Synchronization
You can acheive the synchronization using the 'synchronized' keyword.
The keyword synchronized is used to acquire a exclusive monitor lock on an object. It can be used to mark either a method or a block of code. In both cases, it means to acquire a lock for the duration of the method or block, and to release the lock at the end. It also takes a parameter, which names the object whose lock will be acquired.
Examples for using synchronized keyword
-------------------
suresh
-
Junior Member
Re: Is it possible for the developer to apply Synchronization
In web tier, we can synchronize a block of code inside service()/doGet()/doPost() methods to ensure Thread safety. Alternatively we can implement SingleThreadmodel which is evil by nature and should be avoided.
In business tier, it is not recommended to use synchronization in enterprise beans. Synchronization should be left to enterprise container.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules