Results 1 to 3 of 3

Thread: Is it possible for the developer to apply Synchronization

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    2

    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?


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    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


  3. #3
    Junior Member
    Join Date
    Jul 2007
    Answers
    2

    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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact