Any Difference on synchronize whole and parts?

I want to know any difference between two codes:
Code 1
public class Client {
  private Model model=new Model();
  public synchronized int getId() {
    return model.getId();
  public static void main(String argv) {
    Client c=new Client();
    System.out.println(c.getId());
public class Model {
  private int id=1;
  public synchronized int getId() {
    return id;
Code 2
public class Client {
  private Model model=new Model();
  public synchronized Model getModel() {
    return model;
  public static void main(String argv) {
    Client c=new Client();
    System.out.println(c.getModel().getId());
public class Model {
  private int id=1;
  public synchronized int getId() {
    return id;
}Is Code 2 more risky?
Because my model has a lot of methods, i don't want to rewrite every one on the client. Please comment two codes!
Thank you!
Leo Tai

Code 1 is redundant and would also affect performance to some degree.
Code 2 is better than Code 1.
If there are no setting methods on Client for setting the model, then you may also remove the synchronized keyword from getModel(). Avoid synchronizing methods if there is no use for it.
If id is an int then the synchronized on getId can also be removed.
Assignment to variables of any simple type except long or double is atomic. You don't have to worry about a thread preempting a method in the middle of the assignment. In practice, this means that you never have to synchronize a method that does nothing but return the value of (or assign a value to) a boolean or int instance variable.
Regards,
Tarun

Similar Messages

  • Is any difference in oracle 11i and oracle 12 interfaces tables

    Dear All,
    Can someone tells me .. Is any difference in oracle 11i and oracle R12 interface tables?? My company want to upgrade Oracle 11i to EBS R12
    PS
    Edited by: PS on Jul 13, 2012 3:07 PM

    Please also see:
    Identifying Data Model Changes Between EBS 12.1.3 and Prior EBS Releases
    https://blogs.oracle.com/stevenChan/entry/ebs_data_model_1213
    EBS File Comparison Report Now Available
    https://blogs.oracle.com/stevenChan/entry/ebs_file_comparison_report_now
    EBS Seed Data Comparison Reports Now Available
    https://blogs.oracle.com/stevenChan/entry/ebs_seed_data_comparison_reports
    Thanks,
    Hussein

  • Is there any difference in oracle database and forms database

    i want to know is there any difference in oracle database and forms 6i database
    ,if i import some file through oracle database then same data will exist in forms database or not
    thanks

    Oracle Forms is a Rapid Application Development (RAD) tool not a database. With Forms, you connect to an Oracle database to query and display data from the database as well as insert new or update existing data. Consequently, if exists in the database - you should be able to display it in a Form.
    Craig...

  • Any differences between 2nd generation and 3rd genration i-touch

    any differences between 2nd generation and 3rd genration i-touch.
    thanks

    Game performance is about 10% faster with the 3g, and Apple claims overall speed is 50% faster - though it's hard to tell the difference in everyday usage. The 3g has faster wireless. Most important, the 3g has a maximum of 64gigs storage, which can be very convenient when you're juggling videos, mp3s, podcasts, and audiobooks.

  • Is there any difference between DDR3 memory and LPDDR3 memory? As i brought my macbook air 2013 recently and i saw the specifications it is indicating DDR3, buy apple website stated LPDDR3. Anyone can advise on this?

    Hi
    Is there any difference between DDR3 memory and LPDDR3 memory? As i brought my macbook air 2013 recently and i saw the specifications in the system info that is indicating DDR3, but apple website stated LPDDR3. Anyone can advise on this?

    Welcome to Apple Support Communities
    Read > http://en.wikipedia.org/wiki/Mobile_DDR DDR is the RAM used in computers, and LPDDR is common in mobile computers

  • Difference between Synchronization Wrappers and Unmodifiable Wrappers

    Hi,
    I am not clear abt. the "Difference between Synchronization Wrappers and Unmodifiable Wrappers" in Collection implementation.
    How Unmodifiable Wrappers make read-only access to your data structures?
    Is it thru deep cloning of objects? If that is the case where this is mostly being used?

    You might find it useful to look at the Collections class source code in src.zip.
    It will answer both questions.
    The Unmodiferable wrapper just a wrapper, no cloning occurs. Only the collection wrapped is protected. If you have collections inside collections they will not be protected.
    The unmodifiable wrapper would be used to ensure a collection is not modified by third party code. It could be used if you return a Collection to ensure the caller does not 'accidently' modify it.

  • Any difference between Master data and User master data ?

    Any difference between Master data and User master data ?

    hi
    A user master record defines the authorizations assigned to a user. Based on these authorizations one can access the master data.
    Master data - it is the data which is used long term in SAP r/3 system such as vendor master , material master, customer master,
    there is no such thing like user master data to the best of my knowledge
    hope this helps
    regds
    Manan

  • Is there any difference between the iPod and the iPod hp?

    I'm new to iPods so forgive me if this is a foolish question but I've been thinking for a few weeks now about getting my daughter the shuffle. I bought the 1gb iPod shuffle hp today in Staples because they had it on sale but I'm wondering if there's any drawbacks to buying this one compared to buying it directly from Apple? As far as the electronics, is there any difference between the iPod and the hp iPod?

    Welcome to Apple Discussions!
    Electronically, there is no difference. The only difference comes in support. Apple allows you to call them for 90 days and one issue after you buy them, supporting windows and macs. HP will only help you if you are using a windows, however that support lasts one year. Keep in mind that if you need support, you'll have to go to an HP authorized repair center or another one of HP's options as the apple repair site and apple stores can't help in that regard.
    btabz

  • Is there any difference between an unlocked and sim free iPhone?

    Is there any difference between an unlocked and sim free iPhone?

    I think in the context you're using, they are pretty much the same thing. The only carrier on the planet as of this writing with the CDMA iPhone, which does not use SIM cards AT ALL, is Verizon in the U.S.
    There is a difference between an unlocked iPhone and an iPhone sold without a contract, but still locked to a carrier.
    This list details all of the currently supported iPhone carriers. http://support.apple.com/kb/ht1937
    Some carriers sell phones that are NOT carrier locked (i.e. SIM FREE). Some sell locked phones, but offer unlocking services for their subscribers. In SOME countries, unlocked phones can be purchased directly from Apple. Apple also sells locked phones, that do not require a term commitment with the carrier at what is usually the same price as an unlocked phone.

  • JSF Datatable - Any difference with JSF1.1 and JSF 1.2

    In my project there are lot of Datatables, which retrieve data from the database and display it to the user. For each datatable, the columns are not fixed. I want to create some kind of component that can be reusable.
    It is basically a JSF portlet. Now i have to use RAD 6. RAD 6 supports only JSF1.1. I have to migrate this to RAD7 in the near future. Are there any differences between the Datatable in JSF 1.1 and JSF 1.2?
    I had this approach in mind.
    a) Create the datatable programmatically and put the contents to panelgrid. This way the jsp code will be minimized. Is it a good option.? Are the APIs same in both the versions?
    b) Is it possible to create a custom datatable which can take some key as input. Then based on the key the datatable can be populated with as many columns as desired.
    Please let me know if there are any other good options.
    ~Anitha.

    Doublepost. Please don't use the back button to edit a topic, you're going to repost it. Use the edit button. Continue here: [http://forums.sun.com/thread.jspa?threadID=5336694].

  • Any difference on US iPod and other areas iPod for other languages display

    hi, i hv not owned any ipod yet but plan to get myself a 60GB ipod. i just curious is there any difference between ipod sold in US and ipod sold in Asia? i m asking this as i will be relocated in US for a while and plan to get one there, just curious my file info like ID3 tag is store in simplified chinese and also japanese can b displayed properly in ipod.
    thanks in advance to any expert especially those who already have tried and experienced on this to help out!! appreciate it!!
    regards,
    jacko.

    my file info like ID3 tag is store in simplified
    chinese and also japanese can b displayed properly in
    ipod.
    I think the ID3 tags may need to be converted to Unicode. There is a program called ConvertZ which some people use to do this for Chinese.

  • Any differences between inner join and join without any keyword(inner join)

    Are there any differences between following two join statements?
    Join Statement 1:
    select column1, column2 from table1 t1, table2 t2 where t1.t1Key=t2.t2Key;
    Join Statement 2:
    select column1, column2 from table1 t1 inner join table2 t2 on t1.t1Key = t2.t2Key;
    Thanks for your reply.
    Kevin

    Hi, Kevin,
    user13531850 wrote:
    Are there any differences between following two join statements?To the system, those two are equivalent. They will produce exactly the same results, and will probably result in the same execution plan, so they will be equally efficient.
    Some people find it easier to read and understand one rather than the other. Personally, I find the ANSI syntax (JOIN ... ON ...) easier to understand. The join conditions that apply to each table are listed right next to the table; you don't have to hunt through a long WHERE clause to find them. Also, it makes debugging easier. If you forget the join condition, then you get a syntax error, pinpointing where you forgot the join condition. Using the old syntax, if you forget a join condition, you get a cross-join, and it may not be obvious that any error occurred, but even if you do notice the mistake, you have no clue where it happened.
    Join Statement 1:
    select column1, column2 from table1 t1, table2 t2 where t1.t1Key=t2.t2Key;This is the old join syntax. It works in all versions of Oracle (so far).
    Join Statement 2:
    select column1, column2 from table1 t1 inner join table2 t2 on t1.t1Key = t2.t2Key;This is the ANSI join syntax. It works in Oracle 9.1 and higher. The keyword INNER is optional.

  • Is there Any difference Between OBPM 10g And AlBPM 6.0

    Hello Friends
    I would like know is There any difference between the Oracle BPM 10g and ALBPM 6.0 . ??
    The second one is Difference between AlBPM5.7 and ALBPM 6.0
    Thanks In Advance
    with Regards
    Sandeep
    Edited by: user12036530 on Oct 18, 2009 9:08 PM

    For 10g Differences, check out: http://download.oracle.com/docs/cd/E13154_01/bpm/docs65/upgradeguide/deliverables/upgrade_guide/c_Head_Reference.html
    And other 10g Documentation: http://download.oracle.com/docs/cd/E13154_01/bpm/docs65/index.html Specifically: Upgrade Guide, Process API Differences (if you use PAPI)
    For 6.0 Differences, check out the Documentation: http://download.oracle.com/docs/cd/E13165_01/albsi/docs60/index.html Specifically: ALBPM 6.0 New Features Overview
    Hope this helps,
    -Kevin

  • Is there any difference between "jsp:useBean" and "scriptlet" ?

    A few days ago, I asked similar question. But I didn't get the answer I wanted.
    I want to know the differnce between <jsp:useBean../> and <% .. %>(scriptlet).
    I tested in three environments(Oracle Jserv, OC4J, and Apache Tomcat).
    In Oracle Jserv and OC4J, a problem occured. But, Apache Tomcat does not occur a problem.
    For example,
    1) TestClass.java (Bean)
    public class TestClass {
    private String txt;
    public class TestClass {
    txt = "Test"; ----- (g
    public String getTxt() {
    return txt;
    2) test.jsp
    <html><body>
    <% TestClass test = new TestClass(); %> ---(h
    <%= test.getTxt() %>
    </body></html>
    Assume that I visit "http://localhost:8888/test.jsp".
    In Tomcat, if I change "Test"(number(g) to "Test1" and compile the browser shows the change.
    But Oracle Jserv and OC4J does not do that. They also show the old String.
    So, I changed <% TestClass test = new TestClass(); %>(number(h) to <jsp:useBean id="test" class="TestClass" />. That is, I changed "Scriptlet" to "JSP useBean Tag".
    Then, Oracle Jserv and OC4J also show the changes.
    To conclude, is there any difference between "JSP useBean Tag" and "Scriptlet"?
    Can't I use a scriptlet (to make a class) in Oracle Servlet Engine?
    Thanks.

    It could be as simple as the JSP not recompiling between java recompiles - ie, it compiles in the link to the old class.
    Try changing the JSP file (add and delete a space) after you change the java code, and then see what happens.
    Jonny
    null

  • Is there any difference between a US and a UK iPad Mini?

    I am able to get an iPad Mini with Retina (32GB) from an American Air base in the UK (my fatehr was in the Air Force) and it's slightly cheaper than getting a UK iPad Mini with Retina (32GB). Is there any difference (apart from the charger in the box) between the two?

    BearMan705 wrote:
    the origional iPad so I could just use her charger (not sure if it's compatible)
    The original ipad uses a different connector than those of the 4th generation and later.

Maybe you are looking for