Setters and getters in my beans - syncrhonize

All,
have a bunch of POJO's. Using hibernate. Should I syncronize my setters and getters?

It depends if you would use the object concurrently or not. Even if you did use an instance concurrently, you would not need to synchronize on every getter and setter. I strongly suggest you learn the ins and outs of thread safety before arbitrarily locking your objects.

Similar Messages

  • How to use setters and getters in another program by using bean

    how to use the setters and getters methods using database connection by bean

    Say again?And so he did:
    http://forum.java.sun.com/thread.jspa?threadID=750645
    kind regards,
    Jos ;-)And again
    http://forum.java.sun.com/thread.jspa?threadID=750643&tstart=0
    No, that's his class mate I guess; it must be national getter and setter
    day somewhere today ;-)
    kind regards,
    Jos

  • Setters and Getters

    Can any one Explain  the setters and getters and different ways of writing?? How Can we use it much better??

    http://www.flashscript.biz/flashas3/AS3_tutorial/lesson9.html

  • Regarding Setters and Getters

    Hi All,
    1. How parametters we can send to a Setter ?
    2. What are the best practices of setters and getters?
    Thank you
    Siva

    You should read up on "ENCAPSULATION". Here is a good read for ya:
    http://www.inf.ufsc.br/poo/smalltalk/ibm/tutorial/oop.html
    Thanks.

  • Bean - setters and getters naming conventions

    Hi,
    Just like the constructor is named after the class,
    why shouldn't the setters & getters be named after the
    properties?
    This would make the reflection code clearer.
    Wouldn't it?

    Maybe he means that they should be called:
    void variableName(int value); // setter
    int variableName();  // getter
    Ouch, that was really ugly :)If thats true, our friend is a Delphi programmer :)
    Next we could drop the parenthesis in no arg methods
    v = variableName;
    ahhhh, so much more obfuscating.

  • Why use setters and getters?

    Hi.
    I've been wondering woudn't a function with return do the same thing as a get function with return?
    Ex:
    var age:Number = 16;
    function get Age() {
         return age;
    isn't the same as:
    function Age() {
         return age;
    Thanks.

    I respectfully disagree with the statements that it is a matter of nomenclature. Although there are a lot of cases when accessors (getters/setters) are overused, they are definitely extremely useful features of any OO language. In some case code would be much longer and more cumbersome without accessors. I must say that with code written on timeline accessors are less useful (although I can see plenty of cases one can utilize them). When code is written in classes - accessors are indispensable.
    With your age example it is really a matter of preference. But if you need to do more with age - you would definitely appreciate getters/setters.
    For example:
    Say you have a class Person and it has property age:
    public var age:int = 0;
    Somewhere we instantiate this class:
    var myPerson:Person = new Person();
    Now we set age:
    myPerson.age = 23;
    trace(myPerson.age); // returns 23
    Just imagine you instantiate this variable in 100 of places.
    When you think you are done, your boss comes to you and says: “I want you when they set the age also to evaluate what age group person belongs to.”
    If there were no getters/setters – you would have a very hard time chasing all 100 instances in your program and changing your Person class architecture. With accessors you will spend a few minutes only. You can do the following:
    // change the variable to private
    private var _age:int = 0;
    // create accessors
    public function set age(a:int):void{
         _age = a;
         // here you evaluate age
         if (_age < 10) {
              trace("child");
         else if (_age > 10 && _age < 20) {
              trace("teenager");
         else if (_age > 20 && _age < 30) {
              trace("young");
         else {
              trace("too old to bare :-(");
    public function get age():int{
         return _age;
    As you can see you changed the code in one place and while not doing a thing in any of 100 places you instantiated the Person class.
    Again, your boss can come back and ask to restrict the age to people older than 20.
    So may write:
    public function set age(a:int):void {
         if (a > 20) {
              _age = a;
    Again, you met requirements and did not change any code anywhere else.
    One more request from the boss. Say, he wants you to count how many times age was changed. You can use setter to do that:
    private var getterCounter:int = 0;
    public function get age():int {
         getterCounter++;
         return _age;
    You wouldn’t be able to do all these things if there were not accessors.
    Still the use of age variable will stay the same:
    var myPerson:Person = new Person();
    myPerson.age = 34;
    trace(myPerson.age);
    Welcome to scalability and encapsulation. It doesn’t matter what you do when age is set inside Person class – it will not break code anywhere else.
    There are millions more useful cases when getters/setters come handy.

  • How to use javasetters and getters in different classes

    how to use setters and getters in different class so that the setvalue in one class is effect in second class for getting

    If i got your question right,
    make sure your classes are in the same package
    make sure your getters are public/protected
    make sure your code calls the setter before calling the getter
    Kind regards

  • How to get all property names and values of an bean instance at runtime?

    How can I get all property names and values of an bean instance at runtime?
    (The class of the bean instance is dynamic and I can not know before I write the code .)

    Look at Class. It has a way to get at all public methods and attributes.
    If you need to get to private attributes you can do what the Introspector does and expect the methods to follow the Bean pattern and pull the attributes out based upon that. Privates are all hidden from direct access but through the Bean Pattern they can be figured out.

  • How to disable and enable a java bean area's visability?

    I have a large javabean area on my initial canvas when first dispalying my form.
    When I use the SHOW_CANVAS('canvas name') to display another canvas, everything looks fine except that the javabean from my previous canvas is still visible and covering up portions of this new canvas.
    So I tried using the set_property visible for the javabean area in the form and it only got rid of the surrounding edge of the javabean area.
    Last I made some set_custom_property values to send to the bean that would then use java calls to enable and disable the beans visability.
    But once the beans visibility was disabled in Java then it wouldn't come back after the calls to enable the visibility and refresh the bean were made through Java calls.
    Is there any other ways of disabling and enabling a java bean area's visability?
    Thanks,
    Michelle

    Hello,
    Maybe the bean is always display because of its particular paint() method ?
    Anyway, without any reflexion, I could suggest you to set the bean item width and height to 1 pixel when you don't want to display it. (Set_Item_Property)
    Francois

  • What is the better way to open and close connection in bean

    Hello, may i ask about the best way to open and close the connection?
    At the first, the connection code is store in Conn class bean. The JSP page will call a method in Process bean to process the query and update of database. the Process bean is using th Conn to connect to database.
    In my process bean, it have a method for each type of sql like select, insert, update, and delete for each tables. Each method will call the Conn to open and close the connection. The jsp page can simply call a method retrieve or update records.
    However, when calling the processUpdate method, it is a method that update a group of tables base on the query result of another group of tables and calculation. If I calling the query method in the same bean file, it will open and close the connection many times (more than 1000 times). After open and close the connection several times, the connection to mySQL will be fail.
    Currently, i include 2 method in Process that is only calling the Conn to open the connection and close connection. When calling the openConnection method, it will also set the boolean connected in the class to true and call Conn to open connection. When calling the closeConnection method, it will also set the boolean connected in the class to false and call Conn to close connection.
    After that, i add some change to the query method which is when the connected is false, it will open the connection by calling the Conn and close the connection themself. If the connected is true, it will not call the Conn to open and close the connection because it already connected to the database.
    Now, i when i calling the query method in jsp, it can open the connection and close the connection individually. When i call the processUpdate in the jsp, this method will calling the openConnection before calling the query and calling closeConnection at the end. It not only faster the process(less open and close), it also no cause the connect to mySQL fail error again. However, it also make the coding in the bean file more longer and complex.
    Is there have any better solution?

    Use connection pooling. This will put the connection management in the hands of the webserver, not your code. Check out this post:
    http://forum.java.sun.com/thread.jspa?threadID=741788&messageID=4252932#4252932

  • Problem with IE8 and Flash on LL Bean website

    My desktop machine is running XP SP3 with all updates and the latest Flash Player. When visiting the LL Bean online catalog you view the products which have small pictures associated with them. If you click on a picture a larger window opens up with zoom controls etc which gives you a much better idea of what the product looks like. This works perfectly with my laptop running the same software setup as well as my work computers. With my desktop the image loading progress bar runs to the end of the bar and then just sits there. It doesn't hang IE8 or anything...it just sits and does nothing. I can close the window and go back to browsing the catalog with no problem until I try to view another larger image where it does the same thing.
    So far I have not run into any  issues with any of the other websites I have visited.
    I am hoping the experts here can help me resolve this problem. I have uninstalled and reinstalled flash 3-4 times. I have read several articles on google but none quite like what I'm experiencing...I have run into a brick wall.
    Any help tearing the wall down will be much appreciated.

    It do happen with IE many times. Few flash files works exactly in other browsers but in IE they dont. Try to update the IE latest software or patches from microsoft website.
    Sai.
    My Website - Placement Papers, Interview Questions, Job Openings, Prepaid Mobile Recharge Online, ITClerk

  • Cache Synchronization with JMS and a Message Driven Bean (MDB)

    If I understand correctly, Toplink ueses the following configuration info to find the target to publish its session messages to a JMS server (having its URL as below) which provides the JNDI service that Toplink needs to look up the topic:
    <cache-synchronization-manager>
    <clustering-service> oracle.toplink.remote.jms.mdb.JMSPublishingOnlyClusteringService
    </clustering-service>
    <should-remove-connection-on-error>false</should-remove-connection-on-error>
    <!-- both of the following tags are user specified and must correspond to -->
    <!-- the settings that the user has made, manually, to the JMS Service -->
    <jms-topic-connection-factory-name> jms/TopLinkTopicConectionFactory
    </jms-topic-connection-factory-name>
    <jms-topic-name>jms/TopLinkCacheSynchTopic</jms-topic-name>
    <!-- both of the following tags will be required if OracleAS TopLink -->
    <!-- is not running in the same JVM as the JNDI service that is hosting the JMS Topic -->
    <naming-service-url>ormi://localhost:23791</naming-service-url>
    <naming-service-initial-context-factory> com.evermind.server.rmi.RMIInitialContextFactory </naming-service-initial-context-factory></cache-synchronization-manager>
    The MDB also uses the same JNDI service provided by the JMS server to listen to the topic which is named in the ejb-jar.xml file:
    <enterprise-beans>
    <message-driven>
    <display-name>TopLink clustering MDB</display-name>
    <ejb-name>TopLinkClusteringMDB</ejb-name>
    <ejb-class>com.mycompany.mdb.ClusteringMDB</ejb-class>
    <transaction-type>Container</transaction-type>
    <message-driven-destination> <destination-type>javax.jms.Topic</destination-type>
    </message-driven-destination>
    <env-entry>
    <description>TopLink session name</description>
    <env-entry-name>tl_session_name_for_mdb</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>Employee_Session</env-entry-value>
    </env-entry>
    <resource-ref> <description>description</description>
    <res-ref-name>jms/TopLinkTopicConectionFactory</res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-env-ref>
    <resource-env-ref-name> jms/TopLinkCacheSynchTopic</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type> </resource-env-ref>
    </message-driven></enterprise-beans>
    To do this, the EJB container that hosts the above MDB needs to be configured to know where the JMS server is by using the above URL same as in the Toplink sessions.xml file.
    I am not clear that who provides the JNDI service for the Toplink session name lookup used by the MDB:
    // Obtain the Session name configured in the environment variable
    String sessionName = (String) myEnv.lookup(TOPLINK_SESSION_NAME);
    session = SessionManager.getManager().getSession(sessionName);
    so that the MDB can find the currently running Toplink session and communicate with it.
    Can anybody help answer my above question and correct my understandings?
    Many thanks!

    Although TopLink is running in the application server’s VM, the only notable integration points with the server are for JTA and user-defined data sources. All of the work performed to get a session via SessionManager occurs solely within TopLink. When the call is made to retrieve a session, you aren’t getting the ‘active’ session identified by “Employee_Session” that is registered with the application server, rather a new session is created using the definition that exists for “Employee_Session” in sessions.xml.
    When the call ‘session = SessionManager.getManager().getSession(“Employee_Session”)’ is made, the SessionManager simply looks for sessions.xml at the root level of its deployed jars or classpath, then looks for the “Employee_Session” tag within sessions.xml. If a session exists in the file with that name then a TopLink session object is created and returned.
    Note that setting an environment entry as mentioned above simply allows for the session name to be declared dynamically. The call to ‘myEnv.lookup(“tl_session_name_for_mdb”)’ simply asks the bean’s environment for the <env-entry-value> that matches the <env-entry-name>. That string is then used in SessionManager (no different than a hard coded value would be) to identify the session in sessions.xml that is to be loaded.
    I hope this makes sense.

  • 2 local ejb and one remote session bean in same server - java client

    idea was -
    to create a new stateless session bean that will talk to the two entity beans. although the session bean will expose its method through a remote interface, the communication betweenn the session bean and the entity beans will be through a local interface. the assumptions is that all three ejbs are running in the same JVM.
    so -
    all three ejbs complied properly.
    but -
    when i tried to test with one 'sample test client' then this is the error i get.
    please please -
    can you look into the below error and let me know what possibly i'm doing wrong. i've been trying for last 4 days and can't figure out.
    thanks a lot.
    D:\jdev9052\jdk\bin\javaw.exe -ojvm -classpath D:\jdev9052\jdev\mywork\H&K\EJBApp\classes;D:\jdev9052\j2ee\home\lib\activation.jar;D:\jdev9052\j2ee\home\lib\ejb.jar;D:\jdev9052\j2ee\home\lib\jaas.jar;D:\jdev9052\j2ee\home\lib\jaxp.jar;D:\jdev9052\j2ee\home\lib\jcert.jar;D:\jdev9052\j2ee\home\lib\jdbc.jar;D:\jdev9052\j2ee\home\lib\jms.jar;D:\jdev9052\j2ee\home\lib\jndi.jar;D:\jdev9052\j2ee\home\lib\jnet.jar;D:\jdev9052\j2ee\home\lib\jsse.jar;D:\jdev9052\j2ee\home\lib\jta.jar;D:\jdev9052\j2ee\home\lib\mail.jar;D:\jdev9052\j2ee\home\lib\servlet.jar;D:\jdev9052\j2ee\home\oc4j.jar;D:\jdev9052\opmn\lib\optic.jar;D:\jdev9052\jdev\system9.0.5.2.1618\oc4j-config\.client;D:\jdev9052\lib\xmlparserv2.jar;D:\jdev9052\lib\xmlcomp.jar TeamStaffSessionEJBClient
    context initialized
    javax.naming.NamingException: Lookup error: java.net.ConnectException: Connection refused: connect; nested exception is:
         java.net.ConnectException: Connection refused: connect [Root exception is java.net.ConnectException: Connection refused: connect]
         at com.evermind.server.rmi.RMIContext.lookup(RMIContext.java:153)
         at javax.naming.InitialContext.lookup(InitialContext.java:347)
         at TeamStaffSessionEJBClient.main(TeamStaffSessionEJBClient.java:17)
    Caused by: java.net.ConnectException: Connection refused: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
         at java.net.Socket.connect(Socket.java:452)
         at java.net.Socket.connect(Socket.java:402)
         at java.net.Socket.<init>(Socket.java:309)
         at java.net.Socket.<init>(Socket.java:153)
         at com.evermind.server.rmi.RMIConnection.connect(RMIConnection.java:2216)
         at com.evermind.server.rmi.RMIConnection.lookup(RMIConnection.java:1692)
         at com.evermind.server.rmi.RMIServer.lookup(RMIServer.java:678)
         at com.evermind.server.rmi.RMIContext.lookup(RMIContext.java:134)
         ... 2 more
    Process exited with exit code 0.

    After you drop an ejb into the designer, you'll see a <ejb>Client1 instance created for the ejb in the backing bean (i.e. Page1.java). The client instance is a wrapper for the ejb. It contains all the remote methods available on your ejb. In your web app, you can invoke any methods on the client instance as if you're calling methods on a regular java object. The wrapper class knows how to invoke the corresponding methods on the ejb for you.
    -dongmei

  • JSF - Click twice to get actual content and data from back Bean

    Hello,
    maybe an easy thing ... i got a Menu wih commandLink. the BackBean sends back the "from-outcome". After I cklick on a commandLine, the page is called, but some vars are still from page befor. cklicking second time, then it works. The bad thing about this, is, I have Realm, and the LoginPage appears after I click twice. The User sees the protected<page wthout beeing logged in ...
    someone has an idea?
    thx.
    PS.:Bean ist Session-Scope, marked as Stateful.

    Hello,
    thx for the answet. I debugged.
    When I call with the command the next page, I call a Bean which gives back the outcome ti display the next page. the vars i'm reading, i read with another bean, called when i make the content. apparently, when i use this
    context = FacesContext.getCurrentInstance();
    resp = (HttpServletRequest) context.getExternalContext().getRequest();
    System.out.println("Get " + resp.getRequestURI());
    the display says : "/company-db/index.faces"
    the page i'm go to is "registry.faces"
    when I click a second time, then the display is:
    the display says "/company-db/registry.faces"

  • Changing variable in JSF and passing it to bean

    hi, i want to list a table content(this is ok) and i want to create command links(Delete) for all rows so that users can delete rows that they want.For this i used a datatable.To delete a row, i have String deleteCountryByIndex() method in the bean.It should take a parameter from jsp page which is index of country which is wanted to be deleted.For this, i want to use a variable which i can increment it for each row.How can i do this?
    public String deleteByIndex(){
    FacesContext context = FacesContext.getCurrentInstance();
    String paramValue = (String)
    context.getExternalContext
    ().getRequestParameterMap().get("paramName");
    ... here i can take parameter from the page, but i cannot increment it on the page.
    <h:dataTable id="dataC" var="tab" value="#{backingCountry.list}">
    <h:column>
    <h:outputText value="#{tab.country_id}" />
    </h:column>
    <h:column>
    <h:outputText value="#{tab.country_name}" />
    </h:column>
    <h:column>
    <h:outputText value="#{tab.region_id}" />
    </h:column>
    <h:column>
    <h:commandLink value="sil" type="submit"
    action="#{backingCountry.deleteByIndex}">
    <f:param name="paramName" value="5"/>
    </h:commandLink>
    </h:column>
    </h:dataTable>as you see, when i give the parameter 5, it deletes the fifth country.
    how can i use a variable in the value property of f:param ?
    Thanks for any advice.

    That's not the way how to do it.
    There are in general 3 ways to solve this problem.
    1) Bind the h:dataTable to an UIData property in backing bean and use HtmlDataTable#getRowData() to get the row object where the link was clicked.
    2) Use f:setPropertyActionListener instead of f:param, e.g. <f:setPropertyActionListener target="#{bean.tab}" value="#{tab}" />.
    3) Move the action method from the backing bean to the row object itself, e.g. #{tab.delete}.
    For more pointers and hints check this article: [http://balusc.blogspot.com/2006/06/using-datatables.html].

Maybe you are looking for

  • How to use identity column in table which value always start from one?

    Hi all, Hope doing well, sir i created one table which has id with number datatype for which i created sequence and stored procedure so suppose i inserted two row there it's inserting and id is showing 1, 2 again i truncate that table and again i ins

  • How do I consolidate all of my photos to one location

    I have been using iPhoto 6 on my MBP and had it reference all of my photos on an external harddrive. Then I started importing new photos directly from my camera, and I believe it saved them on the my local hard drive somewhere. So now I believe I hav

  • 3rd-party software to make RAID 1 (mirror) on a drive that already has data

    Is there software which lets you simply add a 2nd drive to an already working Mac and make a RAID 1 mirror without waiting for the following: - clone the internal drive to an external for backup - add the 2nd internal drive - erase both internal driv

  • What is SI developer?

    Hello, I wanted to know what is a SI developer at SAP. This is my first foray into SDN and SAP. So, I d really appreciate any help I can get for the following questions without affecting any confidentiality issues. Actually, all I need is an answer t

  • Why does not MBP find Canon's lousiest printer

    Hi, After changing hard drive my MBP does not find my canon LBP5050n printer any more. I have downloaded and installed the CAPTV320_MacOSX_ukEN.dmg driver but cannot find it in sys.prefs, print&fax, options&supplies when looking for the driver in the