Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3391256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:47:02+00:00 2026-05-18T03:47:02+00:00

Out of the below two synchronization strategy, which one is optimized (as in processing

  • 0

Out of the below two synchronization strategy, which one is optimized (as in processing and generated byte code) and also the scenario in which one should use one of them.

public synchronized void addName(String name) 
{
       lastName = name;
       nameCount++;
       nameList.add(name);
}

or

public void addName(String name) {
    synchronized(this) {
        lastName = name;
        nameCount++;
        nameList.add(name);
    }

}

Also what is advisiable way to handle concurrency:

  1. using java.util.concurrent package
  2. using the above low level methods
  3. using Job or UIJob API (if working in eclipse PDE environment)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:47:03+00:00Added an answer on May 18, 2026 at 3:47 am

    which one is optimized (as in processing and generated byte code)

    According to this IBM DeveloperWorks Article Section 1, a synchronized method generates less bytecode when compared to a synchronized block. The article explains why.

    Snippet from the article:

    When the JVM executes a synchronized method, the executing thread identifies that the method’s method_info structure has the ACC_SYNCHRONIZED flag set, then it automatically acquires the object’s lock, calls the method, and releases the lock. If an exception occurs, the thread automatically releases the lock.

    Synchronizing a method block, on the
    other hand, bypasses the JVM’s
    built-in support for acquiring an
    object’s lock and exception handling
    and requires that the functionality be
    explicitly written in byte code. If
    you read the byte code for a method
    with a synchronized block, you will
    see more than a dozen additional
    operations to manage this
    functionality. Listing 1 shows calls
    to generate both a synchronized method
    and a synchronized block:

    Edited to address first comment

    To give other SOers credit, here is a good discussion about why one would use a sync. block. I am sure you can find more interesting discussions if you search around 🙂

    Is there an advantage to use a Synchronized Method instead of a Synchronized Block?

    I personally have not had to use a sync. block to lock on another object other than this, but that is one use SOers point out about sync. blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works. But if I comment out the line Dim objRequest As
I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan
I am using the program below to sort and eventually print out email messages.
As of now I'm using below line to print with out dot's fprintf( stdout,
Solution to original problem (below) may have been discovered. I commented out <identity> ...
I have a few places where I use the line below to clear out
My experience to write a plugin for Firefox is below zero. Is someone out
Out of the box, in MS Reporting Services, the image element does not allow
Out of the box SSRS reports cannot have data exposed in the page header.
Out of order execution in CPUs means that a CPU can reorder instructions to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.