Why use “synchronized” to decorate an object which its type is Vector

Hello,guys.
Recently,I readed the source code of java.util.Observable.Unfortunately,I encounted some problems。In the source code ,there is an object named “obs”.Its type is Vector. As we all know,Vector is thread-safe.why use “synchronized” in below code?
    public synchronized void deleteObservers() {
     obs.removeAllElements();
    }thanks.
Edited by: qiao123 on Dec 21, 2009 7:07 PM

My " NewBie" Definition of Thread Safe :Is of no interest. It already has a definition and that isn't it.I wanted to make clear what my definition is.
The [JLS DEF FOR COLLECTION|http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html] says:
That is the Javadoc for Collections actually, nothing to do with the JLS or Collection.They are authoritative links for Java Language and the discussion in hand, not Fantasies of Lucy Aunty.
So,how do we draw any inference(s) here?Yes, that you have selectively quoted the Javadoc, which goes on to talk about how you have to use it when iterating.Still not answering my question,Sir.
ejp,you seem to have knowledge but you don't have the attitude to forward the same to others or bear what others say,even when initiative has been taken by others to put forward a problem.
P.S : Not all hackers are arrogant and not all arrogant are hackers.
Another P.S : Waste of my time really !!!
Edited by: punter on Dec 22, 2009 1:09 AM

Similar Messages

  • Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    You may have turned on "Object selection by path only" in the "Selection Options".

  • Why do we use cl_gui_cfw= flush method in Object Oriented ALV programming

    Dear Friends,
    Please solve my query regarding control framework. Why do we use cl_gui_cfw=>flush method in Object Oriented ALV programming. I studied and found that this method transfers automation queue to Front end.  But I could not find any further update on this.
    Thanks & Regards
    Amit Sharma

    Generally this is to restrict the traffic b/w frontend and backend. This means that every operation in Control Framework should be first buffered in the backend and synchronized with the frontend at certain points (one of this point is calling synchronization method cl_gui_cfw=>flush ). This explicit order of synchronization is due to RFC call needed for every communication b/w front/back end. So to avoid to many RFC calls we do it only at certain time.
    Please refer [Automation Queue|http://help.sap.com/saphelp_wp/helpdata/en/9b/d080ba9fc111d2bd68080009b4534c/frameset.htm]. I think it explains the concept quite well.
    Regards
    Marcin

  • Why we don't dispose SPList object using or Dispose methods?

    Hi Friends,
    Why we don't dispose SPList object in SharePoint server side object model?
    Could you please explain me indetails.
    Thanks
    Tiru
    Tiru

    SharePoint objects like SPWeb, SPSite holds a reference to an SPRequest object which holds a reference to a SharePoint COM object that is responsible to communicate with the backend SQL server.
    In case that the SPWeb object is not disposed when it is no longer used, then the connection to the SQL server will stay open and the memory allocated by the COM object will stay in memory as the COM object has not been asked to close the connection and to
    release the memory. However, SPList doesn't hold a reference to SPRequest. Hence it doesn't need to be disposed.
    See this for more information: http://blogs.technet.com/b/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx
    Blog | SharePoint Learnings CodePlex Tools |
    Export Version History To Excel |
    Autocomplete Lookup Field

  • Why assertion instead of if statement ?  Which is better to use ?

    Why assertion instead of if statement ? Which is better to use ?

    Never assertion instead of if statement. The two have fundamentally different intents. Using assert to control program flow is a bad idea

  • How to get the Objects which are used in the webi Report.

    Hi Expert,
    I am trying to get the list of  WebI reports and Objects which are present in the report at  BO 4.0.
    I can able to get details  for only the list of reports and universes.
    Could  any one help me to get those details.
    Regards,
    Murali S

    With 4.0, there is no longer a way to do this using just the .NET SDK because the ReportEngine SDK no longer exists for .NET.  Instead, you'll have to look at using the RESTful Web Services SDK for Webi which runs in the Web Application Container Server on your report server (NOT on the web server!)
    RESTful web services are platform-independent and don't require the installation of any SDK files.  Everything is done through standard HTTP Get, Put, and Post commands and the results are returned in either XML or JSON format.  You don't mention which service pack of 4.0 you're on, but the RESTful web services have evolved over the course of the 4.0 service packs, so more recent is definitely better.
    You can find the documentation for this in the "Development Information" section at help.sap.com/bobip40.  There is also a "space" on SCN for this at http://scn.sap.com/community/restful-sdk and there are some links on this page for various resources and sample code.
    -Dell

  • Know the created info objects which are used in which info providers.

    Hi Experts,
    How can we know the zinfo objects which are used in which info providers.

    Hi,
    Either you can check the where used list of Infoobject as suggested by Gaurav, or you can goto transaction SE16 and put the table name as RSDCUBEIOBJ and put the Infoobject name.
    You will get the list of all Infoproviders in which the infoobject is used.
    Regards,
    Durgesh.

  • For Inventory Adjustment : Which Idoc type to be used and why?

    Hi Gurus,
    For Goods Movement in one of the MM-Purch Implementation I used the Idoc type : MBGMCR03
    at that time inventaory was not playing a big role.
    But for now for doing inventory adjustment (Inventory has importance now) which Idoc type to be followed:
    Can I use same Idoc type : MBGMCR03
    Or Shd I go for Idoc type  : WMMBID02
    In some threads I read if MM you shd. go for MBGMCR03 and for IM : WMMBID02.
    But why I dont know the answer...
    Please give me your views on this.
    Thanks
    Amresh

    MBGMCR03  is basically the BDBG idoc type and uses BAPI_GOODSMVT_CREATE to post the goods movement... You can check the documentation for the FM /BAPI  to determine what kind of goods movement is possible. You can look at T158G table to find the t-codes supported. If you can post your inventory adjustment using the BAPI, you can use MBGMCR03, as long as middle ware can support that format...
    As far as the WMMBID02, It uses the IDOC FM (which in turn also uses the MB_CREATE_GOODS_MOVEMENT)..

  • Imlementing synchronized access to shared objects in LabVIEW OOP

    Many objects in object-oriented programming have an
    identity, such as a file, a front-panel object or a hardware device.
    These objects cannot be modelled using present LabVOOP (LabVIEW Object Oriented Programming) objects as
    LabVOOP objects gets copied as wire is branched; multiple different
    wires cannot all represent a single object. This issue has been
    irritating the community of LabVIEW users since the release of LabVOOP
    a few months ago.
    It seems that there is a huge demand for
    objects with unique identity i.e. by-reference objects in LabVIEW. The
    central problem why LabVOOP propably doen't have these objects is the
    difficulty in implementing synchronized access to these objects from
    multiple parallel threads. The problem of synchronized access can be
    divided into two different separate topics. First how the
    sychronization should be implemented in LabVIEW runtime engine. Second
    how this synchronization mechanism should be visible to the developer.
    I'd like to start this thread to discuss these two issues.
    Synhronization under the hood
    Traditionally
    people talk about locking of an object and about get-modify-set pass
    when accessing the object. Locking is traditionally done by acquiring a
    mutex for an object, modifying the object and releasing the mutex so
    that other threads can access the same object instance. This is how
    inter-thread synchronization is traditionally done. However, besides
    the mutex based locking, the computer science community has innovated
    also different kinds of methods on synchronizing the access to objects.
    One way to get object-level synchronization is modify the
    runtime engine so that it only allows a single method of a synchronized
    object to run at any time. This mechanism of syncrhonization is
    implemented in programming languages like O'Haskell, which is a Haskell
    variant with object orirented features.
    Also different
    transactional mechanisms[1,2] have been successful. In transactional
    mechanisms multiple threads are allowed to access a synchronized object
    simultaneously. As each method accessing an object commits their
    changes, they verify that no other object has modified the object
    simultaneously in a manner than would break the transaction. If such a
    modification has occurred, everything is rolled back. Transactional
    mechanism do not suit to every possible situation as not everything can
    be rolled back. For example it's hard to roll back an action that
    somehow modifies the physical world.
    User experience of synchronization
    How
    the synchronization is generally implemented in LabVIEW shouldn't be
    directly visible to the developer end-user. The developer should
    understand the general concepts of synchronization to take full
    advantage of it, but in general the synhronization mechanism should be
    integrated directly to development environment. There should in general
    be no need to acquire a mutex by calling acquire mutex node but instead
    the end-user should be able to specify which data needs synhronized
    access in more sophisticated way.
    In the following I propose a
    mechanism of integrating the synchronized access of by-ref objects to
    the development environemnt of LabVIEW. The proposal is very
    preliminary but I hope it breaks the ice and the community would start
    innovating in how should NI implement the syncrhonization support in
    the user interface of LabVIEW.
    Wire level synchronization
    Only
    methods can access object private data members. In synchronized access
    to the object, it's the methods accessing the private data members that
    need to be synchronized. The private data members are accessed by
    applying unbundle node to the class wire and data is written back to
    the object using bundle node.
    What I propose is the following.
    An unbundle node could either be normal or "synchronized". A
    synchronized unbundle would guarantee the access to the private data
    members in synchronized manner. All data wires originating from
    synchronized unbundle would be of synchronized type, in a little
    similar manner as a dynamic dispatch wire is of special dynamic
    dispatch type. Such a wire must evetually be connected to a bundle
    node. When the wire is bundled back to the originating object, the
    synchronization requirement is released.
    These synchronized
    wires would look somewhat different from normal wires so that the
    developer instantly knows that the wire is synchronized. The developer
    can branch the wire, but only one wire branch can own the synchronized
    type. The developer could easily select which wire would be
    syncrhonized by Ctrl+clicking the wire. Such a wire can be considered
    as a combination of a data and a mutex, even though mutexes don't need
    to be the underlying synchronization method. The wire just guarantees
    that there is a mechanism in the runtime engine that makes sure the
    access to the wire data is synchronized.
    There is a need to wire
    data originating from a non-synchronized wire to a synchronized wire so
    that it can replace the private data member of the class. This is
    accomplished with a new node similar to bundle node, that would allow
    replacing the data in a syncrhonized wire with some data originating
    from a non-synchronized wire.
    The synchronized wire can be
    connected to a front panel controls of special syncrhonized type. This
    way the synchronized wire can originate from a method and allow passing
    the synchronized data to the calling VI and back to another method.
    This is practical for example in a situation when the developer wants
    to run different analyzes to a data class but don't want to rewrite all
    the existing data analysis tools as class members. So the developers
    writes a syncrhonization acquiring getData method that let's the
    calling VI to access the syncrhonized data. Then the developer passes
    this data to an analysis VI and passes the result back to a setData
    method that writes the result back to the class wire.
    There
    will probably be technical problems in allowing the user to connect
    such a synchronized wire to all existing VIs since these VIs. Therefore
    the programming model for all nodes that do not support such
    synchronized wires will be branching the wire and passing the
    non-synchronized wire branch to the node and then bundling the result
    back to the synchronized wire.
    To increase performance and
    decrease unnecessary buffer copies when a syncrhonized wire is
    branched, if the syncrhonized wire continues directly to the new bundle
    synchronized wire node, no buffer copy is made.
    Discussion
    The
    syncrhonized access to a by-ref LabVOOP objects can be implemented in
    multiple ways by National Instruments. The synchronized access should
    be divided to two different and independent parts: 1) the user
    experience of synchronization and 2) the runtime engine synchronization
    mechanisms. As LabVOOP objects have special properties compared to
    other LabVIEW data types, optimal user experience can be gained by
    designing the user experience specifically for LabVOOP objects. From
    user experience point-of-view this syncrhonization mechanism may not
    work for other data types. Separating object syncrhonization from
    synchronization of other data types is advantageous also for other
    reasons. Due to the fact that object data can only be accessed via
    object methods, more advanced synchronization methods may be used with
    objects than can be used with other data types. O'Haskell
    synchronization implementation is an example of this. Integrating the
    synchronization directly to the user interface allows NI to change the
    mehcanisms under the hood, when computer science comes up with more
    advanced methods. Therefore NI could begin with traditional and quite
    easy mutex-based synchronization and later move to more advanced
    perhaps transaction based syncrhonization methods or even combinations
    of multiple different methods.
    I hope this topic generates
    discussion that would help NI to implement an excellent synchronization
    mechanism in LabVOOP. I hope that all talented individuals in the
    community participate this discussion to help NI to reach this goal. I
    also hope that if you just have time, it would be great if you could
    surf the computer science resources to find out what kinds of new
    techniques there exists for synchronizing access to shared resources. A
    Large community may find much more innovative solutions than a few engineers at NI. Let's give NI the power of open source design
    Tomi Maila

    Hello Tomi,
    First, thank you for taking the time to write such a well
    though-out suggestion.  Are you familiar
    with the “LabVIEW Object-Oriented Programming: The Decisions Behind the Design”
    document?  I think the reason we chose to implement a ‘by
    value’ strategy, is that is more in line with the LabVIEW programming paradigm
    of dataflow, and would make sense to most of our LabVIEW users.
    I think your suggestion is interesting, and it does
    highlight the need to think outside of the conventional LabVIEW box and look to
    some of the innovative things other languages do.  However, I think we all agree that
    synchronization takes careful planning and extra work for the programmer.  Even with an ‘ideal’ solution I see no way
    around this.  For LabVIEW users today,
    one great way to get synchronized ‘by reference’ semantics with your objects is
    to use a single-element queue to pass your object.  The queue itself is passed ‘by reference’ and
    is inherently synchronized!  The does
    have the disadvantage of adding one more small layer of complexity to your
    program, but some complexity would have to be introduced in any situation.  The other disadvantage with this is that it
    is not always an intuitive way to implement your program and requires some
    amount of LabVIEW knowledge before one would generally come across this
    technique.
    In any case, I appreciate the time and effort you put in to
    your suggestion.  Please make sure that
    you submit the suggestion formally through the NI Product Suggestion Center so
    that it can be reviewed by some of the decision makers here.
    Thanks again,
    Travis M
    LabVIEW R&D
    National Instruments

  • Why use customized / particular exceptions instead java.lang.Exception

    Hi,
    Do any of you guys know where can I find a theorical statement / explanation about why use particular / customized exceptions instead java.lang.Exception? I am aware that it consumes more resources and becomes a heavier object, as well as the clearness when coding and all that stuff; however, my boss wants to see a tech document where all this is clearly stated. Any resource over there?
    Regards

    It is better to throw specific--or at least module- or
    package-specific--excpetions, rather than Exception,
    because then the caller knows what to expect. However,
    if you declare "throws Exception", the caller can
    still catch IOException, SQLException, etc.,
    separately. He'll just have to be a really good
    guesser as to which ones he should catch.True.
    Also, there's no point in declaring "throws
    NullPointerException." Any method can throw it without
    declaring it. If you generate your own NPE (or other
    unchecked exception) inside the method, then you
    should document it in the javadoc comments, but you
    don't need to put it in the throws clause. It doesn't
    do any harm, but it's redundant and cluttersome.It was an example and I wasn't feeling too creative....excuse me. ;-) But yeah, I've never thrown NPE ever.
    I'm assuming overhead caused by extending classes.At
    the worst, it would be miniscule, or so I wouldthink.
    What overhead is created by extending classes?Hmm, I was under the impression that a class the extended another class, inherited all of the other classes data (variables, etc.). Hence, you get something like this:
    SuperClass1 + SubClass1 + SubClassOfSubcCass1 = Memory usuage for SubClassOfSubClass1.
    Since adding postivie number will always end up increasing data, SubClassOfSubClass1 will use more dtat than SuperClass1.
    Am I wrong?

  • Why use XML

    I can't find any true tangible benefits to using XML
    to transfer data from legacy systems, in comparison to say, using an external file and loading into existing
    schema objects, which we do use.
    We have 4-6 internal systems, and many many external systems, that currently use text or DB links to transfer data around, and of course the manager hears the catch-phrase-of-the-day XML, all time time and wants us to use it. We do a lot of complicated reading of the files, i.e. headers and multiple layers of detail (header & detail lines can have infinite detail lines)
    Can somebody offer up why use XML? (white pages, something I can get proof with) or why not to use it.
    To me, completly different layer of technology, everybody has a "standard", nobody has the same standard.
    More storage in the database (being a DBA I don't like this), and seems to need its own full time employee to manage it (the IT director won't like that).

    SO... you STILL have to get what the file looks like... can't be read from inside the file (like a decent CSV), hasn't somebody realized that keep layout seperate from the data during outside transfers is stupid?
    I understand the tags etc, I guess because disk is free, and networks are faster, lets clog them up with useless info <the tags>. I have loaded/extracted XML from the database (what a PITA that is) before I asked this question.
    My question is, can somebody please point me in a direction of the benefits of using XML to transfer data between systems.
    Why use XML? Why is XML better than a CSV (or formatted text file)????
    What benefits does it have over those file types??
    A great list of pro/cons would be nice... everything on oracle web sites, and google say all basically say the same thing... "use it because it's new and neat"
    Why should we spend hundreds of man hours reinventing the wheel?
    What tangible benefits are there to using it?
    Might be the wrong forum, if so, please point me in the right direction.

  • How to use Synchronized Keyword

    Hi guys,
    Sorry if this is a simple question, but I'm not sure about the following:
    Suppose we have the class,
    Class Foo
    public synchronized void bar1() {...}
    public synchronized void bar2() {...}
    If I have two threads running concurrently, say T1 and T2.
    I know that T1 and T2 can't both be in bar1() at the same time right? [It has to be in some serial order]
    But, can T1 be in bar1() and T2 be in bar2() at the same time?
    I guess the question is, does the synchronized apply to that specific method only? Or rather to the object (which basically limits at most one thread calling that object's synchronized methods)?
    Thanks a bunch! :)
    -Michael.

    Hi Michael,
    In general, when you syncronize a block of code, the execution of the block is syncronized ON an object. Any object can function as a lock, and only one thread can have a lock of one object at a time. If one thread already has a lock on an object and another thread tries to acquire lock on the same object, the latter thread will wait until the lock is released.
    When you use 'synchronized' in method declaration, it means that the execution of the whole method is syncronized on the object itself (NOT class, if the method is non-static. Static method would be synchronized on the .class object.)
    So, if you have more than one syncronized methods, only one of them is executed at a time ON THE SAME OBJECT. The same method can, of course, be executed simultaneously on other objects. Also, if some of the methods are synchronized, but other methods are not, the non-synchronized methods are not affected in any way.
    It might be good to note that these two pieces of code have exactly the same meaning:
    public synchronized doSomething() {
        // do something
    }and
    public doSomething() {
        synchronized (this) {
            // do something
    }Hope this helps.
    Cheers,
    Vesa
    p.s. It's a good idea to design your code so that one thread will have no more than one lock at a time. If it's possible for more than one thread to have lock on more than one object, there may be a risk of the threads dead-locking, which will crash any program...

  • Why Use Fireworks

    We have recently started designing more websites at work and I'm wondering whether we should be using Fireworks. At the moment we use Photoshop and I'm struggling to see the advantage of using Fireworks. The differences between PS and FW seem to have got less and less over the years. I'd appreciate it if someone can tell me why I should be using FW over PS.
    Thanks
    Sean

    Fireworks tool set and workflow is designed for Web layout. Photoshop's tool set and workflow is designed for image editing. Yes, over the years, Photoshop has had more Web tools added and Fireworks has had more image editing and effects tools added, but the basic philosophy of each application remains the same.
    If you use Fireworks for what it's intended - and get good at it - you'll probably find that you are more efficient at producing Web layouts than you are when using Photoshop. The workflow is different, the approach is different, some terminology is slightly different (layers and sub-layers, for example, are used to organize objects, which can be vectors or bitmaps).
    I've seen people try to approach Fireworks as some kind of "Photoshop Limited," which it isn't. (These people are often very frustrated by FW.) Fireworks is a different application with a unique, hybrid approach to layout, design, and export. It was never intended as a general-purpose image-editing application. The underlying, basic assumption with Fireworks is that you will use it to design a Web layout and produce Web graphics (plus some other things). Consequently, all the essential tools and menu commands you need for these tasks are integral to the application and easily accessed.

  • Why use interfaces?

    What is the point in interfaces?
    I understand that you can use them to ensure a class implements certain methods. Why does this need to be done?
    Do they have any other use?
    thank you
    mike

    Interfaces are used for a number of reasons. Consider:
    1. Java is a strongly-typed language which means that any when a method is called on an Object (non-reflectively), at compile-time that method must be known to exist on the Object.
    2. Java does not support multiple-inheritance.
    Now, suppose you decide to implement the Event model. Interfaces are a very powerful way of allowing you to do this. Providing an abstract superclass that has an abstract actionPerformed() method would suffice, but be unnecessarily restrictive (lack of multiple inheritance). So why not define an interface as a "type"? The Object which is being listened to can inform its listeners via this method. It is excellent for encapsulation as the listened-to object is unable to invoke anything else on the listener other than actionPerformed() (or whatever) and cannot do anything naughty that you don't want it to.
    A fundamental principal of OO is to separate interface and implementation. What better way that to make interface and implementation a fundamental part of the language?
    Also consider:
    You have a massive application that uses Set-like objects all over the place. In your code, when creating new ones and passing around references you do so by the class HashSet (and explicitly constructing them). Supose on switching-on your App you find that it performs like a dog and identify that it is poor HashSet performance at fault. You decide to buy-in a superfast Set-like object from a vendor. Oh dear, you have to do a global search-and-replace on all of your code. Had you used Factories and interfaces, though you would have...
    public class CollectionFactory {
      public static java.util.Set newSet() { return new HashSet(); }
      //etc
    //and the implementation...
    public void myMethod() {
      Set s = CollectionFactory.newSet();
      //pass the INTERFACE Set around
    }You now only have to change ONE line to switch implementations. Super! Note this is the entire point of the J2EE specification. Sun define APIs that handle database-connectivity, server-side processing (Servlets) etc etc. and you and I are free to buy the implementation from whichever vendor we prefer.

  • Which Data-Types can be used as Widget Parameters?

    Hi,
    I have been playing about with widgets (specifically widget parameters) for a while now.
    I've got to wondering, exactly which data-types can Captivate turn into widget parameters?
    So far I know that you can use:
    Numbers,
    Strings,
    Arrays,
    Objects
    and Booleans,
    as parameters.
    Which ones am I missing?
    I know some don't work, because I tried storing a MovieClip as a parameter and that didn't work.

    Hi Eccles,
    You can set all basic data types supported in flash viz.,
    1)Numbers
    2)Strings
    3)Arrays
    4)Objects
    Since in Action script , an Object can be anything (array , array of objects , array of objects which by themselves are array of objects and so on ) , you can virtualy send anything as widget params
    But there are two caveats to this
    1)Object References
    -Object References do not have any meaning once the swf is closed.But the widget params have to be stored across sessions.So If you send a reference as part of widget params it is not going to work.
    This is why sending a Movie Clip (which is actually a reference to an Object ) does not work
    If you want to send such things you will have to 'serialize' the object.
    2)Size of the Object that you send
    The size of the object that you send can have an impact on performance.And since any object that you send has to be converted into XML , objects like bitmaps can turn out to be huge and difficult to handle.
    This brings us down to this - you can send any object across as widget param as long as it is small and serialized.

Maybe you are looking for

  • Photos will not sync or be shared

    I have an "old" AppleTV that I upgraded to version 3.0.2 - and its syncing computer is a Mac Mini running Snow Leopard and the latest iTunes and iPhoto. However, when I set to synch photos and hit apply in iTunes, they appear to transfer to AppleTV.

  • Sound production advice

    right her i go so please bare with me. im a film maker and like having awesome sound on my films etc. i did a music production course a few years ago which taught me the very basics to Logic, so im looking for more advice on being able to reprocess t

  • Service Locator and session facade pattern

    What are differences between Service Locator and session facade pattern? For me it seems one and the same. Please explain me in detail. Expecting kind help. Thanks, Rahul Edited by: rahulb1 on Feb 26, 2008 5:07 PM

  • Does gather_stats job hold a lock on the tabs and indxes it analyzes

    Hi, recently we have seen locking issues when gather stats job is run. The wait is 'library cache lock' wait event. Wanted to know what kind of locks does gather_stats job hold on tables and indexes. thanks, Ven.

  • Standby database management quick notes

    Looking for standby database management quick notes